Newby Question - Date Format

  • Using SQL 2000, trying to get output of date to be in MM DD, YYYY format. Can't seem to find it anywhere. Any help is greatly appreciated.

  • look up convert in BOL.

    convert( datetime, @var, <format>)

    Steve Jones

  • I dont see a convert style that would do it, probably the closest is 101 - which would return mm/dd/yyyy. Seems like there should be something better, but this should work:

    declare @Temp varchar(20)

    set @Temp=replace(convert(varchar(20), getdate(),101),'/', ' ')

    set @temp=left(@temp,len(@temp)-5) + ', ' + right(@Temp,4)

    print @temp

    If you using SQL2K I'd create it as a function.


  • I like it. You would happen to know how to start me off with a CASE structure to evaluate the month?

    If you could start me off with something that evaluated 12 as December, I could do the rest. Been working on it all morning, but just getting errors. Thanks for the help.

  • select datename(month, getdate()) will get you the name of the month. If you need to use case it could look like


    when datepart(month, getdate()) = '01' then 'January'

    when datepart(month, getdate()) = '02' then 'February'


    You can fill in the remaining month pieces.




    “He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot

  • you can also use use datename()

    Steve Jones

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

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