Does anyone who how I could put a date into a date field that is the last day of the currnet month? So if a Zap ran today (April) it would return the date: 30/04/2020
Best answer by ikbelkirasan
View originalDoes anyone who how I could put a date into a date field that is the last day of the currnet month? So if a Zap ran today (April) it would return the date: 30/04/2020
Best answer by ikbelkirasan
View originalYou could just run some javaScript with the following logic:
var today = new Date()
, lastOfMonth = new Date( today.getFullYear(), today.getMonth()+1, 0 )
I would do this with a the code action step?
I tried this and it returned the following error:
Error: You did not define `output`! Try `output = {id: 1, hello: "world"};`
Do I need to input any variables?
const today = new Date();
const lastOfMonthDate = new Date(today.getFullYear(), today.getMonth() + 1, 0);
const formatDigits = (digit) => String(digit).padStart(2, "0");
const day = formatDigits(lastOfMonthDate.getDate());
const month = formatDigits(lastOfMonthDate.getMonth() + 1);
const year = lastOfMonthDate.getFullYear();
const lastOfMonth = `${day}/${month}/${year}`;
output = [
{
lastOfMonth,
},
];
const formatDigits = (digit) => String(digit).padStart(2, "0");
const d = new Date();
d.setDate(0);
d.setHours(0);
d.setMinutes(0);
d.setSeconds(0);
d.setMonth(d.getMonth() + 1);
d.setDate(d.getDate() - 1);
const day = formatDigits(d.getDate());
const month = formatDigits(d.getMonth() + 1);
const year = d.getFullYear();
const lastOfMonth = `${day}/${month}/${year}`;
output = [
{
lastOfMonth,
},
];
const formatDigits = (digit) => String(digit).padStart(2, "0");
const d = new Date();
d.setUTCDate(0);
d.setUTCHours(0);
d.setUTCMinutes(0);
d.setUTCSeconds(0);
d.setUTCMonth(d.getUTCMonth() + 1);
d.setUTCDate(d.getUTCDate() - 1);
const day = formatDigits(d.getUTCDate());
const month = formatDigits(d.getUTCMonth() + 1);
const year = d.getUTCFullYear();
const lastOfMonth = `${day}/${month}/${year}`;
output = [
{
lastOfMonth,
},
];
const formatDigits = digit => String(digit).padStart(2, "0");
const d = new Date();
d.setDate(1);
d.setHours(0);
d.setMinutes(0);
d.setSeconds(0);
d.setMonth(d.getMonth() + 1);
d.setDate(d.getDate() - 1);
const day = formatDigits(d.getDate());
const month = formatDigits(d.getMonth() + 1);
const year = d.getFullYear();
const lastOfMonth = `${day}/${month}/${year}`;
output = [{ lastOfMonth }];
Do you think my time zone settings could be a factor?
Yep, I’m using the latest version (also to confirm, there is nothing set in the ‘Input Data’ field).
Also, when I run the test in Zapier, it returns the correct date (30/06/2020). But when the Zap runs with live data, it’s returning 29/06/2020). So it’s odd that testing vs. live is returning different results.
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.