As you wrote, you need year for getting the value.
You can get it as "last day of the month"
Day ( Date ( month + 1 ; 0 ; year ) )
A really cool 'quirk' is the date format
that gives you the last day of the previous month
AND.... FM does math very well, so
Month ( Get ( CurrentDate ) ) + 1 ;
Year ( Get ( CurrentDate ) )
will give you the last day of THIS month. It will fix the leap days and years for you! Supply what ever date you want to know. If you add 1 to the month and then place 0 for the day, you will get the last day for that month & year.
And of course, this is the next step to just give you the number of days for the given month & year.
Day ( Date ( Month + 1 , 0 , Year )
FMP will take the 0 day of a month and make it the last day of the previous month.
So Mar = 3 add 1 = 4
Date ( 4, 0 , 2017 ) is the last day of the previous month or 3/31/2017.
Day of that date is 31, the last day of this month.
Very neat. Thanks Beverly. I didn't know the month/0/Year thing. Or maybe I forgot?? That will work well.
Thank you. It's a simple solution.
So, if you think you will use this often, create a custom function:
fn_GET_day0 ( dt ; numDays )
# return the last day of the month for a given date (dt)
when numDays = 0 or ""
# return the number of days in a month for a given date (dt)
when numDays = 1 or "Y" or "Yes"
[ _m = Month ( dt )
// ; _d = Day ( dt ) // not used here
; _y = Year ( dt )
; _lastDayOfMonth = Date ( _m+1 ; 0 ; _y )
; _result = Case
( numDays ; Day ( _lastDayOfMonth )
Then you can pass the date and a 'toggle' to show the last day of the month or the number of days in a month.
NOTE: supply the date format your system uses, of course!
fn_GET_day0(GetAsDate("24/3/2017");1) // number of days this month
fn_GET_day0(Get(CurrentDate);"") // last day of current month