varchar to date format

  • Hi Experts,

    How can i convert a varchar field consisting of date values like October 02 2008,December 25 2008 etc to 10-02-2008 and 12-25-2008 .Please help

  • Just use the normal cast, then modify the datetime to fit whatever format you need:

    select cast('October 02 2008' as datetime)

    The full command is:

    select convert(varchar(30),cast('October 02 2008' as datetime),101)

    _______________
    bkDBA
    0.175 seconds -- 10 year average margin of victory at the Daytona 500
    212 Degrees

  • Thanks for the quick reply...

    Can i use that column name.I want to convert all the values from that column..

  • Yes, you should be able to...but try it out.

    In fact, the date doesn't even need to be fully formatted:

    select convert(varchar(30),cast('Oct 2 08' as datetime),101)

    _______________
    bkDBA
    0.175 seconds -- 10 year average margin of victory at the Daytona 500
    212 Degrees

  • How can i execute the same for a particular column.I want to convert all the the values in that particular coulmn

  • Ratheesh.K.Nair (10/17/2008)


    How can i execute the same for a particular column.I want to convert all the the values in that particular coulmn

    select convert(varchar(30),cast(MyLongDateField as datetime),101) from MyTable

    _______________
    bkDBA
    0.175 seconds -- 10 year average margin of victory at the Daytona 500
    212 Degrees

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply