Report Design
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Report Design
Message Icon Topic: how do i calculate date diff excluding weekend? Post Reply Post New Topic
Author Message
cathyganda
Newbie
Newbie


Joined: 16 Apr 2012
Online Status: Offline
Posts: 4
Quote cathyganda Replybullet Topic: how do i calculate date diff excluding weekend?
    Posted: 16 Apr 2012 at 10:45pm
Hello, i need to calculate date difference (in seconds) excluding weekends between two dates. Please please please help?

Thank you
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet Posted: 17 Apr 2012 at 6:11am
this is always a pain...
the outline is something like:
determine your start date (day of week) and your end date (day of week). If the day of weeks cross the weekend, subtract the number of seconds (since you datediff is in seconds) for the weekend...probably would want the datediff as a number of days (if your time span can be greater than a week) then you use that determine the number of weekends that you need to subtract.
 
I would double check, but I am pretty sure that Sunday equates to a 1 and Saturday is the 7 when you use the DayOfWeek function.
 
HTH
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 17 Apr 2012 at 10:00pm
DateTimeVar startdate := {table.datefield1};
DateTimeVar enddate := {table.datefield2};

Numbervar weekdays:=

Datediff("d", startdate, enddate) -
Datediff("ww", startdate, enddate, crSaturday)-
Datediff("ww", startdate, enddate, crSunday);
 
weekdays * 86400
 
This will count the total difference in days between your two dates and then deduct all Saturdays and Sundays.
 
Regards,
Ryan.
 
EDIT: Didn't realize you wanted seconds.... the above has been amended to work assuming your enddate and startdate don't contain a time element ie 01-Jan-2012 00:00:00, a more complex formula will be needed if your end/start dates contain a time.
 
Regards,
Ryan.


Edited by rkrowland - 17 Apr 2012 at 10:06pm
IP IP Logged
crystalsonic
Groupie
Groupie


Joined: 26 Jan 2012
Online Status: Offline
Posts: 46
Quote crystalsonic Replybullet Posted: 15 Jan 2015 at 12:31pm
I am in need of a calculation like the one requested in this post, but I have a time element as well. I need to the date/time difference in hours excluding weekends. Any help is much appreciated.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.