Skip to main content

I am trying to create a site workflow that runs at the beginning of each month that looks at a list and counts the entries for the previous month.

 

I created the logic to figure out the numbers for the month number of the last month, the year of last month (January would be year - 1) and the end day of last month depending on the month. My goal was to use these numbers to create a start date (mm/01/yyy) and end date (mm/dd/yyyy) but I can't seem to figure out how to create a date from those numbers. Setting them as a variable date doesn't work, calculate date doesn't work because you would have to have 0/00/0000 which it sees as blank. 

 

If I run it on the first of each month I could get the begin date by the current date - one month and the end date by subtracting one day from the beginning of the month. But, I want to be able to run this say on the 2nd or 3rd of the month manually if need be also, which wouldn't work.

 

Anyone able to suggest the best way to go about this?

use convert value action


You can calculate the last day of the month by subtracting 1 day from the first of next month

The first of next month is found by

Get the day of the YourDate - fn-formatdate(YourDate ,dd) into ThisDay

calculate 1- ThisDay

Add this value (in days) to the YourDate to get FirstOfThisMonth

Add 1 month to this date

Now subtract 1 day from that result


Maybe this will help, as I needed to calculate a due date on a form to be the last day of the current month. This is the formula I used, which maybe you can adapt to meet your requirements:



 



dateAdd("days",
dateDiff("TotalDays",dateNow(),date(
convertToNumber(formatDate(dateNow(),"YYYY")),
sum(convertToNumber(formatDate(dateNow(),"M"))+1)
,1)),
dateNow())



 



What the above does is find the number of days between the current date and the first day of the next month, and then adds the number days to the current date.


Reply