65.9K
CodeProject is changing. Read more.
Home

Get Only DateTime Part without using Convert

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Jun 10, 2011

CPOL
viewsIcon

16310

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[^].