I want to retrieve the date of the last day of the current month.
e.g.
31.01.05
28.02.05
31.03.05
etc.
Perhaps one could take the first day of the following month and subtract one day, but I don't know how to do this? Has someone a tip for me?
How to retrieve the last day of the current month
Started by
Andi
, Apr 02 2005 12:11 PM
4 replies to this topic
#1
-
Posted 02 April 2005 - 12:11 PM
lastDayOfThisMonth = 30daysMonths = 04,06,09,11 leapYears = 08,12,16,20 ; formattime, currentMonth,%a_now%, MM formattime, currentYear,%a_now%, YY ; IfEqual, currentMonth, 02 { if currentYear in %leapYears% { lastDayOfThisMonth = 29 } else { lastDayOfThisMonth = 28 } } else { if currentmonth in %30daysMonths% { lastDayOfThisMonth = 30 } else { lastDayOfThisMonth =31 } } msgbox, The last day of this month is the %lastDayOfThisMonth%(th/st)
#2
-
Posted 02 April 2005 - 01:17 PM
Good solution. I like date challenges so here's another one that seems correct:
if A_MM = 12 { NextMonth = 01 Year := A_YYYY + 1 } else { NextMonth := A_MM + 1 NextMonth = 0%NextMonth% ; Add leading zero. StringRight, NextMonth, NextMonth, 2 ; Remove inappropriate leading zero, if any. Year := A_YYYY } FirstDayOfNextMonth = %Year%%NextMonth%01 FirstDayOfNextMonth += -1, day ; Subtract one day to yield last day of this month. StringMid, LastDay, FirstDayOfNextMonth, 7, 2 ; Extract just the day. MsgBox Last day of this month: %LastDay%
#3
-
Posted 02 April 2005 - 02:11 PM