July 7, 2008 at 4:35 pm
I want to create a table X1 with a datetime field StartDate and format it as "dd-mmm-yyyy hh:mm:ss". Is defining the format of a field possible?
July 7, 2008 at 6:41 pm
From Books on Line (BOL)
Date and Time (Transact-SQL)
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/tsqlref9/html/9bd1cc5b-227b-4032-95d6-7581ddcc9924.htm
Then more from BOL
CAST and CONVERT (Transact-SQL)
specifically CONVERT ( data_type [ ( length ) ] , expression [ , style ] )
Remember unless you use a user defined data type a column is defined using a Data Type in your case DateTime. You format the information not in the column but when displayed using the Convert function. I would think that a style value of either 13 or 113 would be adequate
July 7, 2008 at 7:32 pm
alijaffaromran (7/7/2008)
I want to create a table X1 with a datetime field StartDate and format it as "dd-mmm-yyyy hh:mm:ss". Is defining the format of a field possible?
For way to many reasons to list all of them here, do NOT format a datetime in a table... like BitBucket said above, only do that during display... never store formatted anything... 😉
If you serve different timezones, you need to change from formatted date back to datetime, add the timezone offset, and then reformat again if you have formatted dates.
If the requirements change on the format, you need to change everything instead of just a simple display.
You can't do date math on formatted dates without at least an implicit conversion.
You can only sort certain formats but it's still a bad idea.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply