March 19, 2003 at 6:44 pm
What is the best way to format the current date to a 5 character string that consists of MM/DD where MM is the month number and DD for the day with leading zeros where required? (eg. March 4 would be 03/04)?
Thanks in advance
March 19, 2003 at 8:38 pm
The date is stored internally in SQL Server in its own format. The client display depends on what is set on the client system.
If you want to convert it you can use the CONVERT statement (see BOL)
Steve Jones
March 19, 2003 at 8:42 pm
Select Convert(Char(5),GetDate(),101)
March 20, 2003 at 11:53 am
Thanks. "Select Convert(Char(5),GetDate(),101)" gives me exactly what I asked for.
However, I used the wrong example to illustrate my question. What if I want "MM/YYYY"? Do I have to get fancy and do it like this?
Select Convert(Char(2),GetDate(),101) ++ '/' ++ right(Convert(Char(10),GetDate(),101), 4)
Thanks
Billy
March 20, 2003 at 12:35 pm
Select substring(convert(char(10), GetDate(), 103), 4, 7)
--
Chris Hedgate @ Apptus Technologies (http://www.apptus.se)
March 20, 2003 at 2:41 pm
Saving a cpu cycle
Select Right(Convert(char(10),getdate(),103),7)
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply