Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 return date part only

Author  Topic 

eugz
Posting Yak Master

210 Posts

Posted - 2013-09-13 : 11:48:09
Hi All.

I'm using SQL Server 2008. I table datetime fild display value like 2008-09-22 15:24:00.000.
How to modify function
DATEADD(DD, 0, DATEDIFF(DD, 0, DateField)) as Date
to get result like mm/dd/yyyy?

Thanks

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-09-13 : 12:02:09
You can use the CONVERT function to convert and format the date as a string, but that is really something you should let your presentation layer handle.
SELECT CONVERT(VARCHAR(10), GETDATE(), 101)


http://technet.microsoft.com/en-us/library/ms187928.aspx

EDIT: Forgot code sample
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2013-09-13 : 15:23:20
You can just cast it to a date. CAST(getdate() as date)
Go to Top of Page

jeffw8713
Aged Yak Warrior

819 Posts

Posted - 2013-09-13 : 15:23:43
You can just cast it to a date. CAST(getdate() as date)
Go to Top of Page
   

- Advertisement -