formatting datetime

  • I have a date field in varchar format in the table. It's in 2/2/2002 format but I want it in 02/02/2002 format. How can I do this?

    I used convert(datetime,a.datehired,100) and other combinations but nothing works. Is it possible at all?

    Thanks,

    Kiran

  • select

    right('0' + cast(datepart(month,a.datehired) as char(2)), 2)

    + '/'

    + right('0' + cast(datepart(day,a.datehired) as char(2)), 2)

    + '/'

    + cast(datepart(year,a.datehired) as char(4))

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg
  • Well, ignoring issues of ambiguity (dd/mm/yyyy or mm/dd/yyyy?)

    select convert(varchar(10),convert(datetime, '2/2/2002'),101)

    works fine for me.

  • Yes, this worked for me. Thanks!

Viewing 4 posts - 1 through 3 (of 3 total)

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