Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of Mondays in (daterange)

Status
Not open for further replies.

5lights

MIS
Nov 19, 2003
53
US
I'm sure this must be easy...but I'm loopy

How can I determine the number of Day(2)(Mondays) in a date range.
I had a RunningTotal of Day(2), but it misses the day if there is no datarecord on that day.
 
You could try this:
DateDiff("ww",{StartDate},{EndDate},crMonday)


Bob Suruncle
 
Known: 07/01/2005 thru 09/30/2005 has 91 days
breaksdown as 11-Mondays, 13-T,W,TH & 14-Fridays

However the datediff returns a '13', regardless of how I stipulate the fourth option('firstdayofweek').

This is going to be compounded by the fact that my daterange will be variable as well as the Day().

More background: Trying to compute TTL_Min_Reserved for resources that have Reservations such as 1300-1400 every M,W,F. I know this is 360min every week, but my daterange is not even on the week, so I have to base it on days.....
hummmm---I'm goig to try another angle...this datediff may still work on the WEEK if I modify the #ofWeeks based on Starting/Ending days being < or > DAY variable...
 
Boy am I loopy....my KNOWN day counts are OFF.
I think I may have the solution soon though, so I'll let you know what I get.
Thanks
 
This appears to work...not yet tested on other dateranges


NumberVar DOW := DayOfWeek(Minimum({@APeriod_S}));
NumberVar DOW2 := DayOfWeek(Maximum({@APeriod_E}));
NumberVar NOWk := DateDiff("w",{@APeriod_S},{@APeriod_E});

// {@Day} is Day() in Reservation
If {@Day} < DOW and {@Day} <= DOW2 then NOWK
else if {@Day} = DOW and {@Day} >= DOW2 then NOWk +1
 
I'd better quit for the day......
I'm getting a headache from hitting my head on the desk.


Any other suggestions on finding the number of Day()(Monday, Tue, Wed, Thur, Fri) in any given daterange?
 
Try this formula

Code:
NumberVar Array CountDays;
Redim CountDays [7];
Local DateVar CheckDate := {?StartDate};
Local NumberVar i;
LOcal StringVar Display;

While CheckDate <> {?EndDate} + 1
Do
(
    CountDays [DayOfWeek (CheckDate, CrMonday )] := CountDays [DayOfWeek (CheckDate, CrMonday )] + 1;
    CheckDate := CheckDate + 1
);

For i := 1 to 7 
Do
    Display := Display & WeekdayName (i, False, crMonday) & " = " &  cstr(CountDays[i],0,"") & " day(s)" & chr(13);


"Between " & {?StartDate} & " and " & {?EndDate} & " there are :- " & chr(13) & Display

HTH

Gary Parker
MIS Data Analyst
Manchester, England
 
HooooooYaaaa;
Thats the ticket.
It returned the right numbers.
Thanks [2thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top