get latest day from the previous month

L

Laurent M

hello,

i'm coding in VBA and i would like, with my date variable, to get the
latest day from the previous month

thanks
 
J

Jim Vierra

What is the "latest" day. Is it the last day of the previous month.
Previous month is Month - 1.

Last day of Month could be gotten by myDaye = Date("mm/01/yyyy") - 1
(pseudo code) where mm is the current month and yyyy is the current year.
The date object set to the first of the month minus one will always be the
correct last day of the previous month for any date. (barring any MS bugs in
the date arithmatic or a new Y2K bug)

Use DateDiff I believe.
 
J

Jim Vierra

Sorry - I'm getting Alzheimer's

Dim d As Date
d = Month(Now()) & "/" & "1" & "/" & Year(Now())
d = d - 1
MsgBox d
 
S

Steve Jorgensen

hello,

i'm coding in VBA and i would like, with my date variable, to get the
latest day from the previous month

thanks

DateAdd(Interval:="d", Number:=-Day(Date()), Date:=Date())
 
K

Karl E. Peterson

Laurent said:
hello,

i'm coding in VBA and i would like, with my date variable, to get the
latest day from the previous month

DateSerial(Year(Now), Month(Now), 0)
 
D

David C. Holley

Or, if I remember by coding correctly...

varDate = CDbl(firstDayOfThisMonth)-1
And then convert it back to a date using the function which I can't
recall at the moment.

David H
Come on baby lite my fire: www.spreadFireFox.com
 
J

Jim Vierra

There is a "firstdayofweek" pseudo argument (placeholder) that is intended
to be replaced by a constant vbMonday/vbSunday etc. This is used to set the
calendar for dates so when we parse out the date by weekday number the
number corresponds to different conventions. I sunday day 1 or is monday
day 1???

There is not similar convention for month as the first day of hte month is
always "01".

Cool huh!
 

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