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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Format of date

Author  Topic 

fabianus76
Posting Yak Master

191 Posts

Posted - 2006-02-24 : 15:59:27
I would like to output a certain date format. In Access I do it like that :

SELECT format(mydate,'yyyymmdd') as mydate FROM mytable

Could someone tell me how to do this in sql-server 2005 ?

Thank you very much!

Regards,
Fabian

my favorit hoster is ASPnix : www.aspnix.com !

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-02-24 : 16:00:51
Check out the different styles of the CONVERT function in SQL Server Books Online. Style 112 will give you that format.

Tara Kizer
aka tduggan
Go to Top of Page

fabianus76
Posting Yak Master

191 Posts

Posted - 2006-02-24 : 16:18:41
Hey Tara!

Thanks for this quick help!!!

Regards,
Fabian

PS I like this format function of Access - no need to keep in mind the 112 or whatever :-(

my favorit hoster is ASPnix : www.aspnix.com !
Go to Top of Page

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-02-24 : 16:22:19
U don't have to keep in mind, me neither
That's y there is BOL
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-02-24 : 16:48:08
>>PS I like this format function of Access - no need to keep in mind the 112 or whatever :-(

Formatting is not *supposed* to be easy and convienant in SQL Server. It's not designed to do it!

Formatting should always be done at the client; SQL should return datetime data back for dates, not varchar()'s in a particular format.

If you return formatted VARCHAR's, when the client wants to format, peform calculations, sort, or do anything with that date, it will immediately need to cast it BACK to a datetime! In addition to now needing to deal with parsing the varchar() in the date format you chose to put it in.

Just return DATA from your database.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-02-25 : 02:14:42
I agree, of course, but why does Query Analyser have to display dates with a width of 54 characters?

SELECT GetDate() (in "Results in Text" mode)



Kristen
Go to Top of Page
   

- Advertisement -