Not applicable

## Calculate the end of a month

I'm looking for simple solution to calculate the last date of given month.

Currently I have a file name which has a date in it's name in format yyyyMM. After parsing this, Nintex reads correctly year and month, but sets day to the first month of the year, where I'd like it to set for the last day of the month.

Are there any easy ways of doing so?

Tags (3)
4 Replies
Nintex Newbie

## Re: Calculate the end of a month

Hi Jerzy,

Not sure if you got this working. What I had to do was to write a function in SQL server which will get month end date. But I needed a function because I wanted an option to get last business day of the month and the actual last day of the month.

So if you write function and put it on your sql server and call if from your workflow passing a date that you need the end date for.

Regards

Bhuti

Not applicable

## Re: Calculate the end of a month

If your date is the first day of the month, use a "Calculate Date" action add one month and subtract one day. This should give you the last day of the given month (works even with leap years).

Example:

01.02.2012 + 1 month = 01.03.2012 - 1 day = 29.02.2012

Nintex Newbie

## Re: Calculate the end of a month

Thank you Martin, this will come in very handy.

Regards

Bhuti

Automation Master

## Re: Calculate the end of a month

I've used two methods in the past to fetch similar date values. With one I had to have a workflow calculate the date with a UDA and in others, I provided a calculated date vale to the workflow by using a formula within a calculated field.

Vadim Tabakmanâ€Œ has provided several UDA's that can help User Defined Actions - Vadim Tabakman , such as the Get Last Day of this month http://vadimtabakman.com/nintex-workflow-date-user-defined-actions.aspx http://vadimtabakman.com/nintex-workflow-date-user-defined-actions.aspx

The only thing I did differently was us the following function to determine business days. First you get the last day of the month, check if it is a weekend, if it is, keep rolling back a day until it isn't. I first do a comparison, then loop the condition until I get a business day. The condition is not(equals(formatDate({var},"dddd"),"Sunday") ) AND not(equals(formatDate({var},"dddd"),"Saturday") )

The other method is to use a calculated date in the list item. This is not always an option, but when it is, using a calculated field with the return type as a Date can be very powerful. My formula to return last business day this month

LastBDSameMonth

=IF(WEEKDAY(

(DATE(YEAR([MyDate]),MONTH([MyDate])+1,1)-1)

)=1,(DATE(YEAR([MyDate]),MONTH([MyDate])+1,1)-1)-2,IF(WEEKDAY(

(DATE(YEAR([MyDate]),MONTH([MyDate])+1,1)-1)

)=7,(DATE(YEAR([MyDate]),MONTH([MyDate])+1,1)-1)-1,(DATE(YEAR([MyDate]),MONTH([MyDate])+1,1)-1)))