Date Formatting

Date Formatting

by Alon -
Number of replies: 1

Hi, 

I'm having some trouble with formatting of dates. My dates are formatted as: M:D:Y (For example, April 1, 2011). I used the following command to generate a new variable from the string:

generate date 2 = date(date, "MDY")

I then had a new variable, date2, in the form of a number (eg April 1, 2011 is 18718). Then I reformatted using:

format %td date2

Which  gives me the value correctly as April 1, 2011. However, when I use the following command:

format %tm date2

I don't get the month and year - instead I get an incorrect value (it transforms into 3519m11 - or November in the year 3519). Can you help me properly format my value into M:Y format?

Thank You,

Alon

In reply to Alon

Re: Date Formatting

by Kristen -

Try this: 

format date2 %td
gen yearmonth=mofd(date2)
format yearmonth %tm