Subtracting Months

R

REGREGL

Hello all,

I have a report with column headings that are dates. These are displayed in
mm-yy format. The first column is todays date =date(). The next 11 columns
need to display the previous 11 months. I had set it up as the second column
being =date()-30 and the next column =date()-60, and so on and so forth. The
problem is (which you may have already figured out) is that when we get to a
certain point of the month and on certain months 30 days doesnt necessarilly
equate to the previous month (such as on Jan 31st). In that event, I would
have two Jan-08 columns (which I do not want).

Do any of you have a solution to this problem?

Thank you in advance!!!
 
K

KARL DEWEY

Use the DateAdd function like this ---
DateAdd("m", -1, Date()-Day(Date())+1)
DateAdd("m", -2, Date()-Day(Date())+1)
DateAdd("m", -3, Date()-Day(Date())+1)
DateAdd("m", -4, Date()-Day(Date())+1)
etc.
Day(Date()) return the day of month - today 31.
Date()-Day(Date()) subtract today's number from today resulting in last day
of last month.
Date()-Day(Date())+1 adds one day to give the first of the month.
 
R

REGREGL

Thank you very much! That fixed the problem!

KARL DEWEY said:
Use the DateAdd function like this ---
DateAdd("m", -1, Date()-Day(Date())+1)
DateAdd("m", -2, Date()-Day(Date())+1)
DateAdd("m", -3, Date()-Day(Date())+1)
DateAdd("m", -4, Date()-Day(Date())+1)
etc.
Day(Date()) return the day of month - today 31.
Date()-Day(Date()) subtract today's number from today resulting in last day
of last month.
Date()-Day(Date())+1 adds one day to give the first of the month.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top