gregc72
Novice

Date calculation for the days of last month

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?

0 Kudos
Reply
3 Replies
emha
Collaborator

Re: Date calculation for the days of last month

use convert value action

0 Kudos
Reply
graham
Apprentice

Re: Date calculation for the days of last month

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

0 Kudos
Reply
David-
Scout

Re: Date calculation for the days of last month

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.

0 Kudos
Reply