Page 1 of 1

LAST DAY of The Month given YEAR and MONTH

Posted: Tue Sep 20, 2011 10:47 am
by kbsuryadev
Just wanted to share a solution.


Input:

YEAR=2011 (YYYY)
MONTH=2/02 (M/MM)


Output: Date

2011-02-28


Code:
StgMonth
If MONTH EQ 12 Then StringToDate(YEAR+1: "-" :"01": "-" :"01","%yyyy-%mm-%dd") ELSE StringToDate(YEAR: "-" :Right('00': ( MONTH+1),2): "-" :"01","%yyyy-%mm-%dd")

StgJulianDate
JulianDayFromDate(StgMonth)

StgLasyDat
DateFromJulianDay(StgJulianDate-1)


Posted: Tue Sep 20, 2011 2:58 pm
by ray.wurlod
So, in words, "the day before the first day of the next month".