Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Number of working days remaining in a month Post Reply Post New Topic
Author Message
louisville2k10
Groupie
Groupie
Avatar

Joined: 13 Sep 2010
Location: United States
Online Status: Offline
Posts: 45
Quote louisville2k10 Replybullet Topic: Number of working days remaining in a month
     Posted: 11 Jan 2011 at 10:16am
Hi,
 
In my report, a user selects a date, {?startdate}. Based on their selection, I need a formula, {projection}, to count the number of working days (M-F) that have passed in the month belonging to the date selected.
 
For an example, if I were to select 1/11/2011, then I would want the formula to give me "7" - the number of working days elapsed in 11/2011 as of the date selected.
 
Could anyone pleeease help me?
Thanks for your help!
IP IP Logged
louisville2k10
Groupie
Groupie
Avatar

Joined: 13 Sep 2010
Location: United States
Online Status: Offline
Posts: 45
Quote louisville2k10 Replybullet Posted: 14 Jan 2011 at 6:33am
Does anyone have any advice they could add here? I'm in a pinch and haven't been able to find a similar issue on any other forum.
Thanks for your help!
IP IP Logged
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Posted: 19 Jan 2011 at 9:02am
I found this in CR help for the "DateDiff" command.  It might work for you.   I did some tests and this code will correctly count the number of work days if the start date is a Saturday or Sunday.  If it is a MTWTF, the count seems to be 1 day off.  You might have to add 1 to the formula if the start day is MTWTF. Good Luck.
 

For example, suppose you want to calculate the number of days between the order date and ship date, excluding Saturdays and Sundays:

Rem Basic syntax

Dim d1, d2

d1 = {Orders.Order Date}

d2 = {Orders.Ship Date}

formula = DateDiff("d", d1, d2) - _

            DateDiff("ww", d1, d2, crSaturday) - _

            DateDiff("ww", d1, d2, crSunday)


//Crystal syntax

Local DateTimeVar d1 := {Orders.Order Date};

Local DateTimeVar d2 := {Orders.Ship Date};

DateDiff ("d", d1, d2) -

     DateDiff ("ww", d1, d2, crSaturday) -

     DateDiff ("ww", d1, d2, crSunday)



Edited by JohnT - 19 Jan 2011 at 9:38am
IP IP Logged
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