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!

Determine how many Sundays are in date range

Status
Not open for further replies.

benny4129

Programmer
Jan 19, 2007
12
US

I have written a Newspaper Carrier program that only delivers on Monday-Saturday. I need to know how to determine how many Sundays are within a certain date range and then subtract them from the total days calculated so I will come up with the correct days to bill for.
I have the following code:
Code:
IF PIA:PrepaidFor = '1 Month'
  PayMonth = Month(PIA:ReceivedFrom)
  IF PayMonth = 1 OR PayMonth = 3 OR PayMonth = 5 OR PayMonth = 7 OR PayMonth = 8 OR PayMonth = 10  OR PayMonth = 12
    PIA:ReceivedTo = PIA:ReceivedFrom + 31
  ELSIF PayMonth = 4 OR PayMonth = 6 OR PayMonth = 9 OR PayMonth = 11
    PIA:ReceivedTo = PIA:ReceivedFrom + 30
  ELSE
    PIA:ReceivedTo = PIA:ReceivedFrom + 28
  END
END
This works good as long as there are only 4 Sundays between PIA:ReceivedFrom and the results of PIA:ReceivedTo
Example:
If PIA:ReceivedFrom = 07/08/2015
PIA:ReceivedTo = 08/08/2015 with only 4 Sundays in between. This is the correct answer.

But if PIA:ReceivedFrom = 07/10/2015
PIA:ReceivedTo = 08/09/2015 but should be 08/10/2015 because there are 5 Sundays in between.
How do I determine there are 5 Sundays so I can add an extra day to PIA:ReceivedTo.
 
Hi,

you can try this way:

Code:
    SUN# = 0
    LOOP i# = DEFORMAT('10.07.2015',@d17) TO DEFORMAT('10.08.2015',@d17)
      IF i# % 7 = 0 THEN
        SUN# += 1
      END
    END
    message(SUN#)

cagiv
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top