How to format Date field?

  • Hi, All

    I have a column that contains Date format like this: 2000-10-09 00:00:00.000

    I dont have a problem to separate YY & MM & Date using DATEPART function. However when I do that, if date is before 10th, it shows up with 1 instead of 01.

    My q is how can I make it show up like "01"?

    Thx in advance.

    Jay

  • --Try:

    -- set up parameter

    declare @Date datetime

    set @Date = '01 jan 2002 12:00:00.000'

    -- convert date into text format

    select convert(varchar(30), @date, 106)

    --or take day part and pad with leading zero

    if len(day(@date)) = 1

    select '0' + cast(day(@date) as char(1))

    else

    select day(@date)

  • ThX davidT

    It is working..

    I used Convert text format..

    Jay

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

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