Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / SQL

Get Only DateTime Part without using Convert

5.00/5 (2 votes)
10 Jun 2011CPOL 16.3K  
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)