Last business day of january

Hello friends, in my process I need take ever the last business day of january and actual year.

How I can ever take the last business day of january of actual year??

Exple: 29/01/2021

Thx!

This is a long one:

Now.AddMonths(-1 * Now.Month + 1).AddDays(Datetime.DaysInMonth(Now.AddMonths(-1 * Now.Month + 1).Year, Now.AddMonths(-1 * CInt(Now.Month) + 1).Month) - Now.AddMonths(-1 * Now.Month + 1).Day).AddDays(If(CInt(Now.AddMonths(-1 * Now.Month + 1).AddDays(Datetime.DaysInMonth(Now.AddMonths(-1 * Now.Month + 1).Year, Now.AddMonths(-1 * CInt(Now.Month) + 1).Month) - Now.AddMonths(-1 * Now.Month + 1).Day).DayOfWeek) = 0, -2, If(CInt(Now.AddMonths(-1 * Now.Month + 1).AddDays(Datetime.DaysInMonth(Now.AddMonths(-1 * Now.Month + 1).Year, Now.AddMonths(-1 * CInt(Now.Month) + 1).Month) - Now.AddMonths(-1 * Now.Month + 1).Day).DayOfWeek) = 7, -1, 0))).

If you need to use a date other than today for the year, replace Now with your datetime variable within the year you want to use. This also assumes there are no holidays in the last week of January.

2 Likes

hello @Anthony_Humphries, thx for help…

This “function” I will put where?

This is the right side of an assign statement. This returns a datetime datatype which can be stored in a variable.

@Anthony_Humphries… WOOOOW Amazing man, Great Thx!

One question, this function ever take the last business of january?

Exple: 29/2021…25/2022…Etc…

Yes, and actually, that’s why it’s so long. The latter half has if statements checking if the last day of the month is Sunday or Saturday. If it’s Sunday, subtract 2 days. If it’s Saturday, subtract 1 day.

1 Like

@Anthony_Humphries

Amazing, work great!!

Thx for help, have a nice day!

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