Assign: Year, Month, and Day parameters describe an un-representable DateTime

Hello all!

I’ve had this assign activity in my workflow for months and it’s never given me issues until today:

New DateTime(now.Year, now.Month, DateTime.DaysInMonth(now.Year, now.addmonths(-2).Month)).tostring(“dd”)

Basically, I just need to capture the number of days 2 months ago. I keep getting the error in the title of this post. Any help or easy fix would be appeciated.

You mean…you would like to get total days in July(sep-2) right? i.e 31, from any given months?

Code which you are using inside itself will give you the answer for that…

image

Hi @mss68291
Use Below code to get 2 month before day

Now.Addmonths(-2).Tostring(“dd”)

Regards,
Arivu

@arivu96 - Below code will give current day -2 months…which is always today’s day…

image

OP does not want that… Please read the requirement…

1 Like

Well the result of that today is 9/31/2021 and there is no such date.

If you’re trying to get the number of days 2 months ago, then it’s just the last part of your expression: DateTime.DaysInMonth(now.Year, now.addmonths(-2).Month)).tostring(“dd”)

However, that’s not quite correct. You have to subtract two months from the current date THEN get the year and month, so it will work if it’s January or February and has to flip the year back one.

DateTime.DaysInMonth(Year(DateAdd(“m”,-2,Now())),Month(DateAdd(“m”,-2,Now())))

Cheers!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.