× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Calculating working days
  • From: bmorris@xxxxxxxxxx
  • Date: Thu, 24 Aug 2000 10:22:28 -0400
  • Importance: Normal


>Date: Wed, 23 Aug 2000 16:53:44 -0400
>From: "oludare" <oludare@ix.netcom.com>
>
>Is there a tool or utility that can be use to calculate a date from a =
>given date with a duration of 'n' business days (Mon-Fri).
>(assume no holidays)

Here's an RPG program that does this.  Just remove the code that
handles the holiday file if you don't care about holidays.

Barbara Morris

 * file HOLIDAYS
A          R REC
A            DATE            L
A            DESC          50A
A          K DATE

Fholidays  if   e           k disk    prefix(holiday)
D d1              s               d
D d2              s               d
D d               s             10i 0
D getDayNum       pr            10i 0
D   date                          d   const
D makeWeekDay     pr              d
D   date                          d   const
D   whichway                    10a   const
D dayNum1         s             10i 0
D dayNum2         s             10i 0
D numWeekends     s             10i 0

C     *entry        plist
C                   parm                    d1
C                   parm                    d2

 * Make sure neither date falls on Saturday or Sunday
C                   eval      d1 = makeWeekDay (d1 : 'forward')
C                   eval      d2 = makeWeekDay (d2 : 'back')

 * Get the number of days between the dates
C     d2            subdur    d1            numdays:*days     5 0

 * Get the number of weekends between the dates
 * (Since we made sure we weren't on the weekend, these will
 * be full weekends)
C                   eval      numWeekends = numDays / 7

 * Is there an extra weekend?
 * Monday = 3 ... Friday = 7
 * If d2 has a lower day number than d1, then there is one more weekend
C                   eval      dayNum1 = getDayNum (d1)
C                   eval      dayNum2 = getDayNum (d2)
C                   if        dayNum2 < dayNum1
C                   eval      numWeekends = numWeekends + 1
C                   endif
C                   eval      numDays = numDays - numWeekends * 2

 * Check holidays
C     d1            setll     holidays
C                   if        %found
 * Read through holidays until we get past the current date
C                   read      #Junkf
C                   dow       not %eof
C                   if        holidayDate > d2
 * We've seen all the holidays between our dates
C                   leave
C                   endif
C                   read      holidays
C                   eval      numDays = numDays - 1
C                   enddo
C                   endif
C     numdays       dsply
C                   seton                                        lr

P makeWeekDay     b
D makeWeekDay     pi              d
D   date                          d   const
D   whichway                    10a   const

D days            s             10i 0
D workdate        s               d
D SaturdayNum     C                   1
D SundayNum       C                   2

C                   eval      days = getDayNum (date)

 * We have 1 = Saturday, 2 = Sunday ... 7 = Friday
C                   if        days > 2
C                   return    date
C                   endif

C                   if        whichway = 'forward'
C                   select
 * Saturday + 2 days = Monday
C                   when      days = SaturdayNum
C                   eval      days = 2
 * Sunday + 1 days = Monday
C                   when      days = SundayNum
C                   eval      days = 1
C                   endsl
C                   else
C                   select
 * Saturday - 1 days = Friday
C                   when      days = SaturdayNum
C                   eval      days = -1
 * Sunday - 2 days = Friday
C                   when      days = SundayNum
C                   eval      days = -2
C                   endsl
C                   endif

 * Adjust forward or backward to Monday or Friday
C     date          adddur    days:*days    workdate
C                   return    workdate

P makeWeekDay     e

P getDayNum       b
D getDayNum       pi            10i 0
D   date                          d   const
D days            s             10i 0
D Friday          c                   D'2000-08-04'
C     date          subdur    Friday        days:*days
C     days          div       7             days
C                   mvr                     days
C                   if        days < 1
C                   eval      days = days + 7
C                   endif
C                   return    days
P getDayNum       e


+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---

As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.