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
[sourcecode language=”sql”] SELECT
CAST( FLOOR( CAST( getDate() AS FLOAT ) ) AS DATETIME )
[/sourcecode]

or

[sourcecode language=”sql”] select CAST(
(
STR( YEAR( GETDATE() ) ) + ‘/’ +
STR( MONTH( GETDATE() ) ) + ‘/’ +
STR( DAY( GETDATE() ) )
)
AS DATETIME
)
[/sourcecode]

and you can also try this one

[sourcecode language=”sql”] select Dateadd(dd,0,datediff(dd,0,getdate()))
[/sourcecode]

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

Leave a Reply