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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last Date of the current Month. 4

Status
Not open for further replies.

comnetlimited

Technical User
Oct 7, 2003
68
0
0
PG
Hello everyone,
Using VBscript, Is there a way I can use to find out the last day of the current month.

Why I need this is because I creating a backup script. I schedule it to run on the Last day of the month. That is it creates a folder of the format YYYYMMDD which is the last date of the month and backup the files there. But I also want it to be flexible, that is it can be run anytime I want but still backs it up in the correct folder. If the folder exist already it does not it to create it again.

I will appreciate your help.
 
A starting point:
MsgBox DateSerial(Year(Now), 1 + Month(Now), 0)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PHV & others..
I think I got the solution myself.

sub LastDateOfCurMonth()
dim lstDateCurMonth, fstDateCurMonth, fstDateNxtMonth
fstDateCurMonth="01/" & Month(date) & "/" & Year(Date)
fstDateNxtMonth=DateAdd("m",1,fstDateCurMonth)
lstDateCurMonth=DateAdd("d",-1,fstDateNxtMonth)
wscript.echo "Last Date of Current Month is: " & lstDateCurMonth
End Sub

call LastDateOfCurMonth
 
Brilliant PHV, so setting the day of the month to zero sets it back to the previous day, which is the last day of the month huh? Never would have thought of that. I would have figured it out with a DateDiff and your solution is much better.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top