Handlebar Help - Get the last day of the month
I am trying to get the last day of the month from the current date as a query parameter. The idea would be
if (the current month is 1,3,5,7,8,10) the last day is 31
else if the current month is 4,6,9,11,12 the last day is 30
else if the current year is leap year (divisible by 4) and the current month is 2 the last day is 29
else the last day is 28
I plan to use #compare to write the expression but I am stuck in how to know if it is leap year.
0
Comments
A nice trick is to take the first day of the next month and then substract one day. That would be like this:
{{dateAdd (join "-" (timestamp "YYYY") (add (timestamp "MM") 1) "01") "-86400000"}}
This wont work in december, so you'll need to do an compare for December and then set YYYY-12-31 in that case.
Thao Dinh you could also just do some math do get what you need instead of needing to do a compare. The idea is to:
thank you both!
Tyler Lamparter this works great!
Please sign in to leave a comment.