June 16, 2005 at 6:53 am
As a newbie to TSQL I have searched my reference materials and can't seem to find out how to set the date format in a simple select statement. Can someone enlighten me, please?
When I pull a date field from my database, I get YYYY-MM-DD HH:MM:SS.SSS but I would like to be able to modify the format. I thought I could simply use the "SET DATEFORMAT" function, but can't seem to get that to work.
Thanks in advance for taking the time to help me out!
Austin
June 16, 2005 at 6:59 am
Convert will help you format your date (or datepart)
Vasc
June 16, 2005 at 7:11 am
Thanks, but not sure I see how a CONVERT is going to help. I don't really think I want to convert the data-type, just the format. Isn't that it?
June 16, 2005 at 7:23 am
The format of the displayed date is given by your computer settings
Vasc
June 16, 2005 at 7:55 am
Use CONVERT in your SELECT statement to format the results that are returned by the SELECT statement - this will not affect the underlying data:
SELECT CONVERT(blah blah) as NiceDate, ....
will display a result called NiceDate, format according to your CONVERT statement.
Regards
June 16, 2005 at 8:15 am
Edited to correct fat finger problem
Hi try this bol will explain the convert and cast functions.
DECLARE @SomeDate datetime
SET @Somedate = '2005/05/12'
Select @Somedate,Convert(char(12),@somedate)as "Nice Date"
/*
Returns
2005-05-12 00:00:00.000 May 12 2005
*/
HTH Mike
June 16, 2005 at 8:17 am
Thank you all very much! I think I've got it now!
Austin
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy