Search This Blog & Web

Friday, May 15, 2009

Convert Date time function in SQL Server 2005

I find on many websites and do many exercieses following are the output summary for those.

-- return datetime portion without time (best is from top to bottom)
1. SELECT DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
2. SELECT CAST(FLOOR(CAST(GETDATE() AS FLOAT)) AS DATETIME)
3. SELECT CONVERT(DATETIME, CONVERT(INT, GETDATE()))
4. CAST(CONVERT(varchar, GetDate(), 101) 

1 comment:

Shamas DBA said...

Nice comment kindly also tell us returning date portion and time portion separately.