How to round down to the nearest month

Hi Wapplers,

QQ - How do I round down a date to the nearest month? My expression is as follows so far:

NOW.dateAdd(‘months’, -1)

I am trying to search for records created in the previous month… so I take todays date and deduct 1 month, but I need to round it down to the nearest month.

Thanks

Hi.
Try something like formatDate('yyyy-MM-01').dateAdd('days',-1)
This will give you the last date of the previous month.

Thank you!

Hi there @daves88!

I had to do this quite recently… and I needed to calculate the exact dates, so for example from 23-02-01 to 23-02-28… here are the server action steps I created to do it!

Best wishes,
Antony.

(step icons look different to yours as I’m still using Wappler v3.9.7…!)