Use AMPScript to find first and last days of the month

If you need to calculate the first and last day of the current month in AMPScript, you can do it like this:

Output:

@today: 7/30/2017 8:25:22 PM
@monthOfThisMonth: 07
@yearOfThisMonth: 2017
@firstDayOfThisMonth: 7/1/2017 12:00:00 AM
@nextMonth: 8/30/2017 8:25:22 PM
@monthOfNextMonth: 08
@yearOfNextMonth: 2017
@firstDayOfNextMonth: 8/1/2017 12:00:00 AM
@lastDayOfThisMonth: 7/31/2017 12:00:00 AM

Reference:

2
Leave a Reply

avatar
1 Comment threads
1 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
2 Comment authors
Adam SpriggsMichael Ragan Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Michael Ragan
Guest
Michael Ragan

I have tried using this method in an email, however the “@lastDayOfThisMonth:” keeps returning 1/5/2018 (today’s date is 5/24/18). Any ideas what might be going wrong?

Thanks!