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

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  •  

    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