Hi,
I am trying to find the no of working days between two date time fields. Please suggest me how I can achieve it.
if (!IsWorkingDayOfWeek(date)) { if (num1 >= 1) { --num1; num2 -= 1440; } else { num1 = 0; num2 = 0; } } /// <summary> /// Get Business Closure Calendar Rules /// </summary> private IEnumerable<Entity> GetBusinessClosureCalendarRules(IWorkflowContext context, IOrganizationService service) { // Get Organization Business Closure Calendar Id var organization = service.Retrieve("organization", context.OrganizationId, new ColumnSet("businessclosurecalendarid")); var query = new QueryExpression("calendar") { ColumnSet = new ColumnSet(true), Criteria = new FilterExpression() }; // Add condition to get Get Calander where CalanderId is equal to Organization's businessclosurecalendarid query.Criteria.AddCondition(new ConditionExpression("calendarid", ConditionOperator.Equal, organization["businessclosurecalendarid"].ToString())); // Get Calendar var businessClosureCalendar = service.RetrieveMultiple(query).Entities[0]; return businessClosureCalendar == null || businessClosureCalendar.GetAttributeValue<EntityCollection>("calendarrules") == null ? null : businessClosureCalendar.GetAttributeValue<EntityCollection>("calendarrules").Entities; } private bool IsWorkingDayOfWeek(DateTime date) { DayOfWeek dayOfWeek = date.DayOfWeek; return dayOfWeek != DayOfWeek.Saturday && (uint)dayOfWeek > 0U; }
*This post is locked for comments
Hi Siraj,
Many Thanks for replying to my query. I have removed not in the if statement and this time I am facing different issue.
with the below statements it looks like you are counting only saturdays and sundays between the two dates
if (!IsWorkingDayOfWeek(date))
return dayOfWeek != DayOfWeek.Saturday && (uint)dayOfWeek > 0U;
you need to remove not in the If statement
Regards,
Siraj
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156