Thursday, January 8, 2009

Convert datetime and date formats

SELECT GETDATE()
ResuleSet:2007-06-10 7:00:56.107
The required outcome was only 2007/06/10.
I asked him to come up with solution by using date functions.

The method he suggested was to useSELECT DATEADD(D, 0, DATEDIFF(D, 0, GETDATE()))
I approved his method though, I finally suggested my method using function CONVERT.SELECT CONVERT(VARCHAR(10),GETDATE(),111)
The reason I use this because it is very convenient as well as provides quick support to convert the date in any format. The table which suggest many format are displayed
http://msdn.microsoft.com/en-us/library/ms187928.aspx

No comments:

Post a Comment