Date variable- only month

Hi Guys,

I have a date variable, save in the type below. example 03 Jul 14

DateToday long %dD_m_Y

I would like to extract only the month- March.

Any thoughts?

Thank you in advance,


New Member
Hi Marvin,

If you date information is entered correctly the following code should work for you:

gen monthonly = month(date)

If that doesn't work for you it's probably the date variable that not set up correctly, based on the information provided in your question I expect this will be a problem (hopefully I'm wrong). Try setting up a new date field.

gen eventdate = date(DateToday, "DMY")

Take care, Mike


New Member
Hi Marvin,

Forgot, you need to set the eventdate variable as a double.

gen double eventdate = date(DateToday, "DMY")

Hi Mike,

I encounter this problem again. I have a date variable OCCURED_DT but when I try to extract the year: gen year= year(OCCURED_DT) and got the following message: (218 missing values generated). IT is not working. I have a date variable, why cant I use the year command? Any ideas?


storage display value
variable name type format label variable label

Please disregard my previous message. I found the solution. The problem was that I had a SIF datetime/c variable so I have to change that first. See below.

gen eventdate = dofc(OCCURED_DT)
format eventdate %td
gen month=month(eventdate)