Click here to Skip to main content
15,884,237 members
Articles / Programming Languages / SQL
Tip/Trick

Get Only DateTime Part without using Convert

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
10 Jun 2011CPOL 15.7K   2
This tip will enable you to get DateTime Part in SQL without using Convert
All of us know many techniques to get Datetime part in sql using Convert, but here I found something interesting which will work without using Convert.
Take a look

SQL
SELECT 
    CAST( FLOOR( CAST( getDate() AS FLOAT ) ) AS DATETIME )

or
SQL
select    CAST(
    (
     STR( YEAR( GETDATE() ) ) + '/' +
     STR( MONTH( GETDATE() ) ) + '/' +
     STR( DAY( GETDATE() ) )
     )
     AS DATETIME
     )

and
SQL
select Dateadd(dd,0,datediff(dd,0,getdate()))


Reference Link: Getting Only the Date Part of a Date/Time Stamp in SQL Server[^].

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralWhy do you need this workaround? What are the disadvantages ... Pin
RK KL10-Jun-11 5:19
RK KL10-Jun-11 5:19 
GeneralRe: There is not issues about performance,advantage and disadvan... Pin
RaviRanjanKr10-Jun-11 18:33
professionalRaviRanjanKr10-Jun-11 18:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.