Often I need to get the last day of the month.
my method is kind of ridicules. I assume there is a better way.
Basically I get the first day of the next month and then subtract one day.
Date ( Month + 1 ; 0 ; Year ). Pretty much same as Date ( Month + 1 ; 1 ; Year ) - 1 that you describe.
Excellent method. You can also use zero for the date in the next month, so Date ( 12, 0, 2018 ) returns November 30, 2018.
Thanks.... never knew a zero in the day field return the last day.
KEEP in mind: Last day of previous month
12/1/2018 = first day of DEC
12/0/2018 = 11/30/2018 = last day of NOV
This works well for years with leap day as well!
So to get the last day of the current month:
Let ( gcd = Get ( CurrentDate ) ;Date ( Month(gcd) + 1 ; 0 ; Year(gcd) ) // last day of current month)
gcd = Get ( CurrentDate ) ;
Month(gcd) + 1 ; 0 ; Year(gcd)
) // last day of current month
This is game changer for me.
Keep in mind it works for months too. If you're iterating through months, there's no need to manually check for reaching December and flipping over to a new year.
Date ( 13 ; 1 ; 2018 ) = January 1st, 2019
Date ( 30 ; 1 ; 2018 ) = June 1st, 2020
Lots of cool ways to do this calculation in FMP.
I use the Java Date API for all date stuff with FMP so that same date logic is available from other applications.
Here's a FileMaker example showing your requirement:
Using Terminal (or any other HTTP-enabled application....same logic)
$ curl localhost:4567/getDateInMonth/2018-12-01/last
Note, this was just a simple example for demonstration. Since this would be your API logic, you could have it return whatever you want, pass to it whatever you want, even call any other API behind the scenes as necessary too. All under your control.
Retrieving data ...