views:

38

answers:

1

I have a datetime field which has a value like this 5/11/2010 12:04:20 PM .... I am converting this field convert(varchar, dbo.Clients.CreatedDate,103) as CreatedDate and i get the result as 11/5/2010..... But how to get 11/5/2010 12:04 PM.....

A: 

You can use a different formatting style to include the time component.

For example:

convert(varchar, dbo.Clients.CreatedDate, 131)

All styles are documented here:

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

Ben Hoffstein
@Ben `28/05/1431 12:04:20:000PM` i dont want sec and millisec
Pandiya Chendur
Sorry, that's a different calendar system anyhow. Best solution then may be either to use a canonical format (120) or split up the date into parts (using the DATEPART) function and cast each to a separate varchar in your desired order.
Ben Hoffstein