Obtain previous month from date function

I found this post from 2007 in the forum.

So I'd just wanted an update if there is now any way to obtain the previous month code using the date function?

Background: I regularily get report files by mail at the start of a new month which cover the last month and I'd like to have a shortcut which subtracts one month of the date function to get into the right folder.

Here's an example about how I imagine to get there:

GO "PathToReportFolder\{date-1Month|yyyy-MM}"

You can do arithmetic on dates and times using scripting now.

Please link your account if you need the script writing for you.

I just tried linking my account - it tells me that my registration number is already linked. It's a 5 place registration, might this cause issues with other links for the same licence? Or did I already link but forget about it?

If you email the details to info@... they can check which forum account they are linked to.

(Of course, don't post the details here to the forum as anyone can read them.)

I have sent in the details (Serial, Forum Name and Forum Email). Let me know if anything is missing.

Hello Leo,

I didn't hear yet from the support concerning the linkage of the accounts. How shall we continue? I'd gladly learn more about applying date arithmetic with scripting, but I need some entry points to start from.

Best regards

Here's the script code.

If it's in single-line mode, click Advanced at the bottom of the button editor.

Then set the button's Function: drop-down to Script Function, and paste this in:

[code]@script vbscript
Function OnClick(ByRef clickData)

LastMonth = DateAdd("m", -1, Date())
YYYY = ZeroPad(Year(LastMonth),4)
MM = ZeroPad(Month(LastMonth),2)

Set cmd = clickData.func.command
cmd.RunCommand "Go ""PathToReportFolder\" & YYYY & "-" & MM & """"

End Function

Function ZeroPad(s,c)
ZeroPad = s
Do While (Len(ZeroPad) < c)
ZeroPad = "0" & ZeroPad
Loop
End Function[/code]

Change PathToReportFolder as appropriate.

Great!

I optimised the script for my needs - I had a double subfolder (year/Month in "MM MMM")
And the following script creates and opens the folder in one step.

[code]@script vbscript
Function OnClick(ByRef clickData)
RootPath = "PathToReportFolderRoot"

LastMonth 	= DateAdd("m", -1, Date())
YYYY 		= Year(LastMonth)
MM 			= ZeroPad(Month(LastMonth),2)
MMM			= MonthName(Month(LastMonth), True)

CompletePath = """" & RootPath & YYYY & "\" & MM & " " & MMM & """" 
Set cmd = clickData.func.command
cmd.RunCommand "CreateFolder NAME=" & CompletePath
cmd.RunCommand "GO " & CompletePath

End Function

Function ZeroPad(s,c)
ZeroPad = s
Do While (Len(ZeroPad) < c)
ZeroPad = "0" & ZeroPad
Loop
End Function
[/code]

Thanks for the excellent support.