Solved How can i get last day of month ??

#1
Dear All,

I have tried to get last of month by writing Code , by giving Month and Year values in input fields.
But I am not able to get last day of month , Could you please provide Code (solution's) for this situation.

Note:: Is there any way to get last day of month in Blue Prism.?

Thanks & Regards ,
Gopal.
 
#2
Try this in a calculation
AddDays(FormatDate(AddMonths(Today();+1);"yyyy-MM-01");-1)

Explanation : Add one month to today's date / Format the result to first day of month / Subtract one day from the result (add minus one)
For any other date : replace Today() with a declared variable : [date]
This works for every date even if you are already on the last day of the month.
 
Last edited:
#3
Hello,

You can achieve that in BP with a calculation stage:
DateAdd(9, -1, MakeDate(1, [month] + 1, [year]))
where month and year are your data items

Explanation: Make a date with the first day of the next month. Use DateAdd to increment one day.
 
#4
Gil's calculation blew up for me if month = 12. If you want to create a date function that returns the last day of the month in BP then you need have two calculations and a decision object to branch. If the month is 1 - 11 then use

AddDays(MakeDate(1,[Month]+1, [Year]), -1)

If month is 12 then

AddDays(MakeDate(1,1, [Year]+1), -1)

This can be placed in a custom VBO, see the attached image. But there are so many ways to do this.
 

Attachments

#5
Gil's calculation blew up for me if month = 12. If you want to create a date function that returns the last day of the month in BP then you need have two calculations and a decision object to branch. If the month is 1 - 11 then use

AddDays(MakeDate(1,[Month]+1, [Year]), -1)

If month is 12 then

AddDays(MakeDate(1,1, [Year]+1), -1)

This can be placed in a custom VBO, see the attached image. But there are so many ways to do this.
HI All,

Thank you so much for responses, Every expression is working fine in different situations.

Regards,
Gopal.
 
#6
Try this in a calculation
AddDays(FormatDate(AddMonths(Today();+1);"yyyy-MM-01");-1)

Explanation : Add one month to today's date / Format the result to first day of month / Subtract one day from the result (add minus one)
For any other date : replace Today() with a declared variable : [date]
This works for every date even if you are already on the last day of the month.
HI AyJayBe,

Thanks for you input, but in expression it showing some error please verify it and revert back.

Regards,
Gopal
 
Top