Insert Last Day Of Month

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Joe
Newbie
Posts: 4
Joined: Fri Jul 10, 2009 3:09 pm

Insert Last Day Of Month

Post by Joe » Wed Apr 28, 2010 7:48 pm

Ive been searching through the forums, but have not come across the answer to this. On the first of every month, i need to run a report, two of the fields are date fields. the first one will be the first day of the month. the second field is the last day of the month. How can i make macro scheduler insert what the last day of the month is? Inserting the first day of the month is easy, since it is always the first, but since the last day can be the 28th, 29th, 30th, or 31st, im not sure how to insert the correct date.

any help would be greatly appreciated.

Thank you,

Joe

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Apr 28, 2010 9:14 pm

There might be a more concise way to do this and you might want leading zeros on day and month.

Code: Select all

VBSTART
VBEND

Day>dd
Month>mm
Year>yyyy

VBEval>trim(%dd%),dd
VBEval>trim(%mm%),mm

Let>today=%mm%/%dd%/%yyyy%

Let>kk=
Repeat>kk
  Add>today,1
  Separate>today,/,var
  If>var_1<>mm
    Let>kk=done
    Sub>today,1
  EndIf
Until>kk,done

MDL>First day of the current month is: %mm%/1/%yyyy%%CRLF%Last day of the current month is: %today%

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Here is another way to find last day of month

Post by adroege » Wed Apr 28, 2010 10:00 pm

Here is another way to find the last day of the month
using VBScript.

Code: Select all

VBSTART
Function Last_Day_of_Month(mymonth)
  Last_Day_of_Month = DateSerial(Year(Now), 1 + mymonth, 0)
End Function
VBEND

//Pass in the month number i.e. 1=January 2=February, etc
VBEval>Last_Day_of_Month(2),result
MessageModal>Last Day of Month = %result%
Enjoy!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts