Get Only DateTime Part without using Convert

All of us know many techniques to get DateTime part in SQL using Convert, but here I found something interesting when I was reading an article of BenNadel [ Who he is  ]  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 you can also try this one

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

Reference Link :-  Getting Only the Date Part of a Date/Time Stamp in SQL Server

Advertisements

About Ravi Ranjan Kumar

An Indian who Living, Loving & Learning Technology with different tastes and willing to share knowledge and thoughts.
This entry was posted in SQL Server, Tips&Tricks and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s