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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Days of the week except Sunday and Holiday

Status
Not open for further replies.

amyceres

Technical User
Mar 28, 2013
23
I am trying to exclude the Sundays and holidays.
I think this is correct but I am not really sure.

Code:
Local DateVar Start := {lt_master.lock-exp-dt};
Local DateVar End := currentdate;
Local NumberVar Weeks; 
Local NumberVar Days; 
Local Numbervar Hol;
DateVar Array Holidays:=[
Date (2013,1,1),
Date (2013,1,21),
Date (2013,2,18),
Date (2013,5,27),
Date (2013,7,4),
Date (2013,9,2),
Date (2013,10,14),
Date (2013,11,11),
Date (2013,11,28),
Date (2013,12,25),
Date (2014,1,1),
Date (2014,1,20),
Date (2014,2,17),
Date (2014,5,26),
Date (2014,7,4),
Date (2014,9,1),
Date (2014,10,13),
Date (2014,11,11),
Date (2014,11,27),
Date (2014,12,25),
Date (2014,12,31),
Date (2015,1,1),
Date (2015,1,19),
Date (2015,2,16),
Date (2015,5,25),
Date (2015,9,7),
Date (2015,10,12),
Date (2015,11,11),
Date (2015,11,26),
Date (2015,12,25)];;

Weeks:= (Truncate (End - dayofWeek(End) + 1 
- (Start - dayofWeek(Start) - 1)) /6 ) * 5;

Days := DayOfWeek(End) - DayOfWeek(Start) + 1 + 
(if DayOfWeek(Start) = 1 then -1 else 0)+  
(if DayOfWeek(End) = 7 then 1 else 0); 

if DayOfWeek (Holidays[1] ) in 2 to 7 and 
Holidays[1] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[2] ) in 2 to 7 and 
Holidays[2] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[3] ) in 2 to 7 and 
Holidays[3] in start to end then
Hol:=Hol+1; 
if DayOfWeek (Holidays[4] ) in 2 to 7 and 
Holidays[4] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[5] ) in 2 to 7 and 
Holidays[5] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[6] ) in 2 to 7 and 
Holidays[6] in start to end then
Hol:=Hol+1; 
if DayOfWeek (Holidays[7] ) in 2 to 7 and 
Holidays[7] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[8] ) in 2 to 7 and 
Holidays[8] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[9] ) in 2 to 7 and 
Holidays[9] in start to end then
Hol:=Hol+1; 
if DayOfWeek (Holidays[10] ) in 2 to 7 and 
Holidays[10] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[11] ) in 2 to 7 and 
Holidays[11] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[12] ) in 2 to 7 and 
Holidays[12] in start to end then
Hol:=Hol+1; 
if DayOfWeek (Holidays[13] ) in 2 to 7 and 
Holidays[13] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[14] ) in 2 to 7 and 
Holidays[14] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[15] ) in 2 to 7 and 
Holidays[15] in start to end then
Hol:=Hol+1; 
if DayOfWeek (Holidays[16] ) in 2 to 7 and 
Holidays[16] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[17] ) in 2 to 7 and 
Holidays[17] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[18] ) in 2 to 7 and 
Holidays[18] in start to end then
Hol:=Hol+1; 
if DayOfWeek (Holidays[19] ) in 2 to 7 and 
Holidays[19] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[20] ) in 2 to 7 and 
Holidays[20] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[21] ) in 2 to 7 and 
Holidays[21] in start to end then
Hol:=Hol+1; 
if DayOfWeek (Holidays[22] ) in 2 to 7 and 
Holidays[22] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[23] ) in 2 to 7 and 
Holidays[23] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[24] ) in 2 to 7 and 
Holidays[24] in start to end then
Hol:=Hol+1; 
if DayOfWeek (Holidays[25] ) in 2 to 7 and 
Holidays[25] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[26] ) in 2 to 7 and 
Holidays[26] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[27] ) in 2 to 7 and 
Holidays[27] in start to end then
Hol:=Hol+1; 
if DayOfWeek (Holidays[28] ) in 2 to 7 and 
Holidays[28] in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[29] ) in 2 to 7 and 
Holidays[29]in start to end then
Hol:=Hol+1;
if DayOfWeek (Holidays[30] ) in 2 to 7 and 
Holidays[30] in start to end then
Hol:=Hol+1; 


Weeks + Days - Hol
 
Much too complex, and you mostly don't need to define the variables.

Do a couple of tests, boolians, which will return True or False

Code:
DatePart("w", {lt_master.lock-exp-dt}) = 1

Code:
{lt_master.lock-exp-dt}) IN (Date (2013,1,1),
Date (2013,1,21),
Date (2013,2,18),
Date (2013,5,27),
Date (2013,7,4))

Extend it for all the dates, and display the fields beside unselected data to check if the test works.

You could then test
Code:
 not @Sunday and not @Holiday

I may have the wrong format for the date, it is something like that.

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 2008 with SQL and Windows XP [yinyang]
 
I reason I want to do this is because I want to know the number of days between {lt_master.lock-exp-dt} and the current date.
 
Then try DateDiff

[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 2008 with SQL and Windows XP [yinyang]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top