Set calendar control to last day of Month

  • Thread starter Thread starter Joe Bohen
  • Start date Start date
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
 
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...
 
Joe: Last day of last montth or LDoLM = date()-day(date())

This works across years and in leap years.

Ray
 
Back
Top