I want to get records from sql server 2005 in datetime format like this “dd/mm/yyyy h:m:s”
My database date is default datetime format
AttLogId int
...
DownloadLog datetime
I am trying to retrieve the datetime like this:
SELECT AttLogId ,convert(varchar,DownloadLogDate,103) FROM AttLog
ORDER BY DownloadLogDate
but I only get the date and not the time.
I suggest you don’t try to get the values in a particular string format. Fetch them as
DateTimevalues and then format them in the .NET code usingDateTime.ToString("dd/MM/yyyy H:m:s").It’s almost always worth keeping data in its “natural” data type (date/time here) for as long as possible, only converting to text when you really need to. So your SQL should just be:
How you then retrieve the data will depend on how you’re talking to SQL (e.g. LINQ to SQL, using
SqlDbReaderetc). But you should be able to get it as aDateTimeand then format it locally. This will make it easier to test, easier to debug, give you more control over cultural aspects (date separators, possibly specifying a standard specifier instead of a custom one, etc).