In this article, we'll explain how to create a filter for last month's records using three code snippets.
1. First Day of Last Month
Use this formula to find the first day of the previous month:
DATETIME_FORMAT(DATEADD(DATEADD(TODAY(), -1, 'month'), -(DAY(TODAY()) - 1), 'days'),"DD/MM/YYYY")
2. Last Day of Last Month
Use this formula to find the last day of the previous month:
DATETIME_FORMAT( DATEADD( DATETIME_PARSE( DATETIME_FORMAT( DATEADD(TODAY(), -1, 'month'), 'YYYY' ) & '-' & (VALUE( DATETIME_FORMAT( DATEADD(TODAY(), -1, 'month'), 'MM' ) ) + 1) & '-01', 'YYYY-MM-DD' ) , -1, 'day' ) , "DD/MM/YYYY" )
3. Check if Created Date is Between First and Last Day of Last Month
Use this formula to check if a record's created_date is between the first and last day of the previous month:
AND( OR(IS_SAME(created_date,first_day_last_month), IS_AFTER({created_date}, first_day_last_month)),OR(IS_SAME(created_date,last_day_last_month), IS_BEFORE({created_date}, last_day_last_month)) )
With these formulas, you can easily filter your records to display only those created in the previous month.
The last formula evaluates to 1 if the created_date is between first and last, so this column is the one to use in the filter for the view.