Hi!
Can someone help me get the previous business day in a calendar? Please note that I need to consider if the previous day is a weekend. So if today is Monday, what I need to get is the Friday last week. See sample below.
Thanks!
Hi!
Can someone help me get the previous business day in a calendar? Please note that I need to consider if the previous day is a weekend. So if today is Monday, what I need to get is the Friday last week. See sample below.
Thanks!
DateTime prevDay = date.AddDays(-1)
while (prevDay.DayOfWeek == DayOfWeek.Saturday || prevDay.DayOfWeek == DayOfWeek.Sunday)
{
prevDay = prevDay.AddDays(-1)
}
Regards,
Karthik Byggari
An alternate way -
DateTime prevDay = date.AddDays(-1)
if(prevDay.DayOfWeek = DayOfWeek.Saturday)
prevDay = prevDay.AddDays(-1)
if(prevDay.DayOfWeek = DayOfWeek.Sunday)
prevDay = prevDay.AddDays(-2)
Regards,
Karthik Byggari
Thank you for the feedback. But I’m having a hard time picturing this one.
So I should use IF Activity, and in my condition is ‘if(prevDay.DayOfWeek = DayOfWeek.Saturday)’, and in my then is ‘prevDay = prevDay.AddDays(-1)’. In my else is another if statement with the condition, ‘if(prevDay.DayOfWeek = DayOfWeek.Sunday)’ and in my then is ‘prevDay = prevDay.AddDays(-2)’
Is my understanding correct?
Yes.
Hi Karthik,
I’m not getting perfect results, Can you please provide the xmal.
Thanks
Baba