Jump to content
Macro Express Forums

First And Last Days Of Current Month


oded

Recommended Posts

I need to work with two variables, one containing the first day of current month (eg: 01/11/2005) and the other containing the last day of current month (eg: 30/11/2005)

Of course the variables' content should change according to the date the macro is run.

How can I do that?

 

Thanks for any help,

 

Oded

Link to comment
Share on other sites

Hello Oded!

 

I don't remember if you have the PGM Function Library or not, so here is a short macro that will do what you want. It is written using the Macro Express Text/Date commands utilizing dynamic execution. The macro ends by setting T10 to the first day of the current month and T11 as the last day.

 

// ***
// *** Get the first day of the month and place it in T10.
// ***

// Place today into a variable and then convert it to an integer.
Date: Save DD (19) into %T1%
Variable Modify String: Convert %T1% to integer %N1%

// Decrement it by 1 so that today - value = 1.
Variable Modify Integer: Dec (%N1%)

// Add 100 to the value so that when it is converted back
// to a string we can retain the leading zero.
Variable Modify Integer: %N1% = %N1% + 100
Variable Modify Integer: Convert %N1% to text string %T1%
Variable Modify String: Delete Part of %T1%

// Create a dynamic Macro Express command string that uses the
// above variable and then execute it.
Variable Set String %T2% "<DD/MM/YYYY{YP0%T1%}{P000}10>"
Run Macro in Variable %T2%

// ***
// *** Get the last day of the month and place it in T11.
// ***

// Loop to count the days remaining in the month. Stop
// when we hit the 1st day of the following month.
Repeat Start (Repeat 31 times)
 
 // Add 100 to the value so that when it is converted back
 // to a string we can retain the leading zero.
 Variable Modify Integer: %N1% = %N1% + 100
 Variable Modify Integer: Convert %N1% to text string %T1%
 Variable Modify String: Delete Part of %T1%
 
 // Create a dynamic Macro Express command string that uses the
 // above variable and then execute it.
 Variable Set String %T2% "<DD{YF0%T1%}{P000}02>"
 Run Macro in Variable %T2%
 
 // If we have hit the next month then decrement N1 and exit the loop.
 If Variable %T2% = "01"
   Variable Modify Integer: Dec (%N1%)
   Repeat Exit
 End If
Repeat End

// At this point N1 is still a 3-digit number so convert it to a
// string and just keep just the right-two characters.
Variable Modify Integer: Convert %N1% to text string %T1%
Variable Modify String: Delete Part of %T1%

// Create a dynamic Macro Express command string that uses the
// above variable and then execute it.
Variable Set String %T2% "<DD/MM/YYYY{YF0%T1%}{P000}11>"
Run Macro in Variable %T2%

// Launch and/or activate the Windows Notepad.
Activate or Launch: "notepad" OR "notepad.exe"
Delay 500 Milliseconds
Text Type: T10 = %T10%<ENTER>T11 = %T11%<ENTER>
Macro Return


<REM2:***><REM2:*** Get the first day of the month and place it in T10.><REM2:***><REM2:><REM2:Place today into a variable and then convert it to an integer.><DD{NP000}{P000}01><TMVAR2:05:01:01:000:000:><REM2:><REM2:Decrement it by 1 so that today - value = 1.><NMVAR:09:01:0:0000001:0:0000000><REM2:><REM2:Add 100 to the value so that when it is converted back><REM2:to a string we can retain the leading zero.><NMVAR:01:01:1:0000001:2:0000100><NMVAR:05:01:0:0000001:0:0000000><TMVAR2:11:01:00:001:001:><REM2:><REM2:Create a dynamic Macro Express command string that uses the><REM2:above variable and then execute it.><TVAR2:02:01:<DD/MM/YYYY{YP0%T1%}{P000}10>><RUNMACVAR:2><REM2:><REM2:***><REM2:*** Get the last day of the month and place it in T11.><REM2:***><REM2:><REM2:Loop to count the days remaining in the month. Stop><REM2:when we hit the 1st day of the following month.><REP3:01:000000:000001:00031:1:01:><REM2:><REM2:Add 100 to the value so that when it is converted back><REM2:to a string we can retain the leading zero.><NMVAR:01:01:1:0000001:2:0000100><NMVAR:05:01:0:0000001:0:0000000><TMVAR2:11:01:00:001:001:><REM2:><REM2:Create a dynamic Macro Express command string that uses the><REM2:above variable and then execute it.><TVAR2:02:01:<DD{YF0%T1%}{P000}02>><RUNMACVAR:2><REM2:><REM2:If we have hit the next month then decrement N1 and exit the loop.><IFVAR2:1:02:1:01><NMVAR:09:01:0:0000001:0:0000000><EXITREP><ENDIF><ENDREP><REM2:><REM2:At this point N1 is still a 3-digit number so convert it to a><REM2:string and just keep just the right-two characters.><NMVAR:05:01:0:0000001:0:0000000><TMVAR2:11:01:00:001:001:><REM2:><REM2:Create a dynamic Macro Express command string that uses the><REM2:above variable and then execute it.><TVAR2:02:01:<DD/MM/YYYY{YF0%T1%}{P000}11>><RUNMACVAR:2><REM2:><REM2:Launch and/or activate the Windows Notepad.><LAUNCHYES3:0:0112notepad<LAUNCH:notepad.exe><IMSD:500><TEXTTYPE:T10 = %T10%<ENTER>T11 = %T11%<ENTER>><MRETURN>

Link to comment
Share on other sites

Not directly, but it would be much easier to calculate them because the {DateTime} functions use Julian day numbers. Here is an example:

 

// ***
// *** Get the first day of the month and place it in T10.
// ***

// Generate a date string of the first day of the month.
Date: Save DD (19) into %T1%
Date: Save DD/MM/YYYY (19/03/2000) into %T10%
Replace "%T1%/" with "01/" in %T10%

// ***
// *** Get the last day of the month and place it in T11.
// ***

// Get a date string of this time next month.
Date: Save YYYYMMDD (20000319) into %T2%
Variable Set String %T1% "{ DateTime - Go Months },%T2%,1"
Write Registry String: "PgmFunction"
Macro Run: { PGM Function }
Read Registry String: "ReturnString1"

// Change it to the first day of next month.
Variable Modify String: Delete Part of %T2%
Variable Modify String: Append "01" to %T2%

// Convert it to a Julian day number.
Variable Set String %T1% "{ DateTime - Date to Julian },%T2%"
Write Registry String: "PgmFunction"
Macro Run: { PGM Function }
Read Registry Decimal: "ReturnDecimal1"

// Subtract 1 from it and then convert it back to a date string.
Variable Modify Decimal: %D2% = %D2% - 1
Variable Set String %T1% "{ DateTime - Julian to Date },%D2%"
Write Registry String: "PgmFunction"
Macro Run: { PGM Function }
Read Registry String: "ReturnString1"

// Format the date string.
Variable Modify String: Delete Part of %T1%
Variable Modify String: Copy %T10% to %T11%
Replace "01/" with "%T1%/" in %T11%

// Launch and/or activate the Windows Notepad.
Activate or Launch: "notepad" OR "notepad.exe"
Delay 500 Milliseconds
Text Type: T10 = %T10%<ENTER>T11 = %T11%<ENTER>
Macro Return


<REM2:***><REM2:*** Get the first day of the month and place it in T10.><REM2:***><REM2:><REM2:Generate a date string of the first day of the month.><DD{YP000}{P000}01><DD/MM/YYYY{YP000}{P000}10><TMVAR2:21:10:00:000:000:%T1%/01/><REM2:><REM2:***><REM2:*** Get the last day of the month and place it in T11.><REM2:***><REM2:><REM2:Get a date string of this time next month.><YYYYMMDD{YP000}{P000}02><TVAR2:01:01:{ DateTime - Go Months },%T2%,1><REGWSTR:1:HKEY_CURRENT_USER\Software\Professional Grade Macros\Pgm Functions\PgmFunction><MACRUN2:{ PGM Function }><REGRSTR:2:HKEY_CURRENT_USER\Software\Professional Grade Macros\Parameters\ReturnString1><REM2:><REM2:Change it to the first day of next month.><TMVAR2:11:02:00:007:002:><TMVAR2:07:02:00:000:000:01><REM2:><REM2:Convert it to a Julian day number.><TVAR2:01:01:{ DateTime - Date to Julian },%T2%><REGWSTR:1:HKEY_CURRENT_USER\Software\Professional Grade Macros\Pgm Functions\PgmFunction><MACRUN2:{ PGM Function }><REGRDEC:2:HKEY_CURRENT_USER\Software\Professional Grade Macros\Parameters\ReturnDecimal1><REM2:><REM2:Subtract 1 from it and then convert it back to a date string.><DMVAR:02:02:1:000000000000002.0000:2:1><TVAR2:01:01:{ DateTime - Julian to Date },%D2%><REGWSTR:1:HKEY_CURRENT_USER\Software\Professional Grade Macros\Pgm Functions\PgmFunction><MACRUN2:{ PGM Function }><REGRSTR:1:HKEY_CURRENT_USER\Software\Professional Grade Macros\Parameters\ReturnString1><REM2:><REM2:Format the date string.><TMVAR2:11:01:00:001:006:><TMVAR2:09:11:10:000:000:><TMVAR2:21:11:00:000:000:01/%T1%/><REM2:><REM2:Launch and/or activate the Windows Notepad.><LAUNCHYES3:0:0112notepad<LAUNCH:notepad.exe><IMSD:500><TEXTTYPE:T10 = %T10%<ENTER>T11 = %T11%<ENTER>><MRETURN>

Link to comment
Share on other sites

Thank you Joe for your answers.

I'm afraid I don't understand this:

Variable Set String %T2% "<DD/MM/YYYY{YP0%T1%}{P000}10>"

I don't know what YP0 and P000 mean... Have looked in the help files and in "Macro Express Explained" book but couldn't find.

Can anyone give me some hint?

 

Thanks,

Oded

Link to comment
Share on other sites

What you see is a Macro Express command line in its native mode. How it is used is called "dynamic processing". By placing a native command line in a string variable and then running the variable, we can change the value of a setting in the command line each time through a loop. In this case, we are decrementing %T1% from "today" until the first day of the month is reached.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...