Formatting date in a select statement?

  • 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

  • Convert will help you format your date (or datepart)


    Kindest Regards,

    Vasc

  • 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?

  • The format of the displayed date is given by your computer settings


    Kindest Regards,

    Vasc

  • 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

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  •  

    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

  • 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