Use Code to Get Last Date in a Month for a Provided Date

  • 7 April 2022
  • 0 replies
  • 94 views
Use Code to Get Last Date in a Month for a Provided Date
Userlevel 7
Badge +13

📌  We do our best to ensure that the code in these articles works as advertised, but please be aware that Zapier Support does not officially help with code steps due to their advanced nature. Feel free to comment on the article or ask in the Zapier Community, where we have code-savvy users.

The Purpose

Dynamically get the last date in a month for a provided date.

How to Configure

NOTE: Any valid date format is supported (e.g. date = YYYY-MM-DD)

Copy the Code (Javascript)

let date = new Date(inputData.date);
let y = date.getFullYear()
let m = date.getMonth();

let MonthLastDate = new Date(y, m + 1, 0).toISOString().split("T")[0];
// m + 1 gets the next month
// when 0 is provided as the Day value it will return the last day of the previous month

output = [{MonthLastDate}];

The Result

Contribution by Troy Tessalone

Troy is a Certified Zapier Expert who automates workflows with no-code and low-code apps to help clients save time and make money.


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.