Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Month Problem

Status
Not open for further replies.

jamesmay

Technical User
Jun 1, 2004
41
GB
Hi, i am trying to get the start date and end date of any given month. If Month(Now)-2 falls back into the previous year it has a fit.

Can anyone help!

here is the code i am using...

Mid(MonthName(Month(Now)-2),1,3)
StartMonth = DateSerial(Year(Now), Month(Now)-2 + iOffset, 1)
EndMonth = DateSerial(Year(Now), Month(Now)-2 + 1, 0)
 
thismonth = (Month(Now)-2)
If thismonth < 1 then
thismonth = thismonth+12
thisyear = thisyear-1
end if

gets your offsets properly placed if you're dealing with individual portions of the date


[thumbsup2]DreX
aKa - Robert
 
How about just creating a new date and letting it take care of the work using DateAdd calls rather than handling the rollovers yourself?
Code:
Dim strStartDate, strEndDate, aDate
aDate = DateSerial(Year(Now()),Month(Now()),1)
'start date is aDate - 2 months
strStartDate = DateAdd("m",-2,aDate)
'end date is aDate - 1 month and 1 day
strEndDate = DateAdd("d",-1,DateAdd("m",-1,aDate))

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Cheers guys, i will try both methods out and let you know how i get on.

Cheers for replying.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top