change date by month (1 Viewer)

bbwolff

Registered User.
Local time
Today, 13:43
Joined
Oct 1, 2013
Messages
116
I use textboxes to limit the time periods for report
the defaults are set to first and last day of previous month
I'd like to add a button that would set you a month back/forward, but I'm stuck on how to change values to correspond to first/last day ofprevious month

this is my onload code

LastDay = DateSerial(Year(Date), Month(Date), 0)
FirstDay = LastDay - Day(LastDay) + 1
Me.tdat1 = FirstDay
Me.tdat2 = LastDay
 

smig

Registered User.
Local time
Today, 14:43
Joined
Nov 25, 2009
Messages
2,209
here some examples:

DateSerial(Year(date), 1, 1) ' -- first day of year
DateSerial(Year(date), Month(date), 1) ' -- first day of month
DateSerial(Year(DateAdd("yyyy", -1, Date)), 1, 1) ' -- first day of previous year
DateSerial(Year(DateAdd("yyyy", -1, Date)), 12, 31) ' -- 31 of Dec. of previous year
DateSerial(Year(date), DateAdd("mm", 1, Date), 1) - 1 ' -- last day of month - Go to first day of next month and move one day back
 
Last edited:

Galaxiom

Super Moderator
Staff member
Local time
Today, 21:43
Joined
Jan 20, 2009
Messages
12,852
There are simpler expressions for the last day.
DateSerial understands zero as a day or month.

For example, last day of previous month:
DateSerial(Year(somedate), Month(somedate),0)
 

smig

Registered User.
Local time
Today, 14:43
Joined
Nov 25, 2009
Messages
2,209
There are simpler expressions for the last day.
DateSerial understands zero as a day or month.

For example, last day of previous month:
DateSerial(Year(somedate), Month(somedate),0)
Nice to know
 

Users who are viewing this thread

Top Bottom