How to select date without time in SQL

后端 未结 17 2029
灰色年华
灰色年华 2020-11-28 20:09

When I select date in SQL it is returned as 2011-02-25 21:17:33.933. But I need only the Date part, that is 2011-02-25. How can I do this?

相关标签:
17条回答
  • 2020-11-28 20:52

    Its too late but following worked for me well

    declare @vCurrentDate date=getutcdate()
    
    select @vCurrentDate
    

    When data type is date, hours would be truncated

    0 讨论(0)
  • 2020-11-28 20:52

    In PLSQL you can use

    to_char(SYSDATE,'dd/mm/yyyy')
    
    0 讨论(0)
  • 2020-11-28 20:54

    In case if you need the time to be zeros like 2018-01-17 00:00:00.000:

    SELECT CONVERT(DATETIME, CONVERT(DATE, GETDATE()), 121)

    0 讨论(0)
  • 2020-11-28 20:54

    Use is simple:

    convert(date, Btch_Time)
    

    Example below:

    Table:

    Efft_d       Loan_I  Loan_Purp_Type_C   Orig_LTV    Curr_LTV    Schd_LTV    Un_drwn_Bal_a      Btch_Time            Strm_I  Btch_Ins_I
    2014-05-31  200312500   HL03             NULL         1.0000    1.0000         1.0000      2014-06-17 11:10:57.330  1005    24851e0a-53983699-14b4-69109
    


    Select * from helios.dbo.CBA_SRD_Loan where Loan_I in ('200312500') and convert(date, Btch_Time) = '2014-06-17'
    
    0 讨论(0)
  • 2020-11-28 20:57

    For SQL Server 2008:

    Convert(date, getdate())  
    

    Please refer to https://docs.microsoft.com/en-us/sql/t-sql/functions/getdate-transact-sql

    0 讨论(0)
  • 2020-11-28 20:57
    CAST(
            FLOOR( 
                 CAST( GETDATE() AS FLOAT ) 
            )
    
    AS DATETIME
    )
    

    http://www.bennadel.com/blog/122-Getting-Only-the-Date-Part-of-a-Date-Time-Stamp-in-SQL-Server.htm

    0 讨论(0)
提交回复
热议问题