Set calendar control to last day of Month

J

Joe Bohen

The code
.Month = Month(Date) - 1
.Day = Day(Date) - Day(Date) + 1
.Year = Year(Date)
is used to set the date on a calendar control to the first
of the previous month. How would I set the date to the
last day of the previous month?

Any help much appreciated.
Joe
 
D

Daniel Carollo

Hello Joe!

First of all, the code you posted doesn't work accross years. I would rather
use:
..Month = Month(DateAdd("M", -1, Date()))
..Day = 1
..Year = Year(DateAdd("M", -1, Date()))

To find the last day of the previous month, all you need to know is that
it's the day before the first of THIS month, hence:
..Month = Month(DateAdd("d", -1, DateSerial(Year(Date(), Month(Date(), 1)))))
..Day = Day(DateAdd("d", -1, DateSerial(Year(Date(), Month(Date(), 1)))))
..Year = Year(DateAdd("d", -1, DateSerial(Year(Date(), Month(Date(), 1)))))

Good luck...
 
G

GRayL

Joe: Last day of last montth or LDoLM = date()-day(date())

This works across years and in leap years.

Ray
 

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