Click here to Skip to main content
14,769,451 members
Articles » General Programming » Programming Tips » General
Tip/Trick
Posted 10 Jun 2011

Tagged as

Stats

14.2K views

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
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

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

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

and
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)

Share

About the Author

RaviRanjanKr
Software Developer
India India
No Biography provided

Comments and Discussions

 
GeneralWhy do you need this workaround? What are the disadvantages ... Pin
RK KL10-Jun-11 6:19
MemberRK KL10-Jun-11 6:19 
GeneralRe: There is not issues about performance,advantage and disadvan... Pin
RaviRanjanKr10-Jun-11 19:33
professionalRaviRanjanKr10-Jun-11 19: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.