It is appropriate to use a comma when you are separating the day of the month from the year in a written sentence. A second comma is placed after the year in the sentence. The rest of the sentence comes after the second comma.
Examples:
1) We are having the party on Oct. 4, 2011, in our backyard.
2) Her classes will begin Aug. 22, 2012, at the local community college.
Commas are not used if a part of a date is not present in a written sentence. Leave out a comma if only the month and year are written, or only the month and day are written. The general rule of thumb is that if any part of the date is missing, leave off the comma.
Examples:
1) They were married in January 2011 in Las Vegas.
2) The date of their wedding was Jan. 14 of last year.
If you are writing a sentence with more than one clause that involves a two-part date, such as a month and day or a month and year, a comma comes after the first clause and before the second clause. This is true regardless of whether the date is at the end of the first clause or at the end of the sentence. Normal two-part date rules apply to the date in the written sentence.
Examples:
1) On March 3, she will perform in her first Broadway production.
2) He began his business studies at the beginning of his second semester, in January 2010.
When discussing a number of years not directly related to a date, commas simply divide the clauses of a sentence. Do not place a comma after a number simply because it is a number.
Examples:
1) We have lived in our house for 30 years.
2) In five years, we will move to Arizona.