I am trying to calculate the number of days remaining in a month from the Output Date.
So, for example, the output date is 18/08/2020 - what formula could I use to calculate the number of remaining days from the 18/08/2020 to the end of the month, 31/08/2020.
The output date can be any date of the year so the calculation would need to check what month it is in and how many days in that month.
Any help would be appreciated.
Thanks
Page 1 / 1
Hi @Dainesj!
The cleanest way to accomplish this would be with a Code step. Unfortunately, I’m not super well-versed in Python or Javascript (though others in the Zapier Community are).
I think I could solve this with a couple of Formatter steps, and possibly Google Sheets. My day is wrapping up here, so let me jump back into this tomorrow to see if I can come up with something not too complicated.
Hi @Dainesj,
That is a great question and very useful. Probably I will make a post about such calculations soon. But lets try to help you out on this one now.
Please keep in mind, I am no programmer myself….I got some employees that do that for me. However, I have a bit of experience and do like to create some simple scripts. I played around a bit, and this is what I came up with. You can use this in a code step like @nicksimard explained:
var formatDate = inputData.calcDate.split("/").reverse().join("-"); var d = new Date(formatDate); var lastDay = new Date(d.getFullYear(), d.getMonth()+1, 0);
var datestring = lastDay.getDate() + "/" + ("0" + (lastDay.getMonth()+1)).slice(-2) + "/" + lastDay.getFullYear(); //Remove this if you like, or use it in the output
This requires you to have an input field with the name calcDate which basically gives the date it should use to make its calculations. It would look like this:
This will output a field called daysRemaining and this can be used in later steps again. Within this script you can also output the last day of the date you gave it if you like. For this, add the output variable datestring within the output variable. If now, remove it like stated in the code.
Hope this helps you out. Like I said, I am no programmer so all created based on my own basic knowledge haha. Let me know if you need anything else!
~Bjorn
Thank you @ForYourIT and @nicksimard. I will have a go with this today and let you know if I get it to work. Very much appreciated. Regs, Jon
Well, there you have it! Thanks for the amazing assist @ForYourIT :)
Hi @Dainesj ,
Where you able to complete this or do you still need some additional assistance? If all good, please mark your answer if you like to close this question :D