Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Determine how many Sundays are in date range

Determine how many Sundays are in date range


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
    PIA:ReceivedTo = PIA:ReceivedFrom + 28
This works good as long as there are only 4 Sundays between PIA:ReceivedFrom and the results of PIA:ReceivedTo
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.

RE: Determine how many Sundays are in date range


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


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close