Number of weekdays between 2 dates.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tiernan

    Number of weekdays between 2 dates.

    Hi all
    I'm looking for a way to find the number of weekdays between 2 dates
    In my form I have three fields for a begin date (dd)(mm)(yyyy) and
    three for the end date (dd)(mm)(yyyy)
    Now these values will be stored into a database and at the same time
    there will be an e-mail generated and send to me that contains the
    starting date en the end date . But now I want an extra line in this
    e-mail that tells me howmany days there are between the starting date
    en end date so that the e-mail contents looks something like this.

    Begin date : (dd) (mm) (yyyy)
    End date : (dd) (mm) (yyyy)
    Days between (number of days)

    so lets say
    starting date is 01/01/2003
    end date is 15/01/2003
    then the number of days between should say 11
    (01-02-03-06-07-08-09-10-13-14-15 /01/2003)

    I realy hope someone would be so kind to give me a solution on my
    problem.
    thx a miljion in advanced.
  • Jochen Daum

    #2
    Re: Number of weekdays between 2 dates.

    Hi Tiernan!

    On 4 Sep 2003 01:27:23 -0700, michaeljanssens @bluestripes.be (Tiernan)
    wrote:
    [color=blue]
    >Hi all
    >I'm looking for a way to find the number of weekdays between 2 dates
    >In my form I have three fields for a begin date (dd)(mm)(yyyy) and
    >three for the end date (dd)(mm)(yyyy)
    >Now these values will be stored into a database and at the same time
    >there will be an e-mail generated and send to me that contains the
    >starting date en the end date . But now I want an extra line in this
    >e-mail that tells me howmany days there are between the starting date
    >en end date so that the e-mail contents looks something like this.
    >
    >Begin date : (dd) (mm) (yyyy)
    >End date : (dd) (mm) (yyyy)
    >Days between (number of days)
    >[/color]
    ok, so far you could use mktime to make up a timestamp (if between
    1970 and 2038) and calculate the difference. Divide by 86400 seconds
    per day and round as pleased.
    [color=blue]
    >so lets say
    >starting date is 01/01/2003
    >end date is 15/01/2003
    >then the number of days between should say 11
    >(01-02-03-06-07-08-09-10-13-14-15 /01/2003)[/color]

    When you are talking about working days it gets more interesting. What
    about public holidays, etc. A solution you can do, is to store a table
    with dates and if they are a working day or not and do select count(*)
    from table where date between 'begindate' and 'enddate'. Subtract the
    number from above and you should be fine.
    [color=blue]
    >I realy hope someone would be so kind to give me a solution on my
    >problem.
    >thx a miljion in advanced.[/color]

    you're welcome.

    Jochen

    --
    PHP DB Edit Toolkit -- PHP scripts for building
    database editing interfaces.
    Download PHP DB Edit Toolkit for free. PHP DB Edit Toolkit is a set of PHP classes makes the generation of database edit interfaces easier and faster. The main class builds tabular and form views based on a data dictionary and takes over handling of insert/update/delete and user input.

    Comment

    • BKDotCom

      #3
      Re: Number of weekdays between 2 dates.

      not completely thought-out / finished (therefore not actual code) but...

      weekdays = floor( day_difference/7 ) * 5 // almost there
      // weekday(date) can be 0-6
      if ( weekday(start_d ate) < 6 ) weekdays += 5-weekday(start_d ate)
      if ( day_difference > 7 ) {
      weekdays += weekday(end_dat e)
      if ( weekday(end_dat e) == 6 ) weekdays-- // don't add saturday
      }




      michaeljanssens @bluestripes.be (Tiernan) wrote in message news:<5c66c84b. 0309040027.14b0 ae8a@posting.go ogle.com>...[color=blue]
      > Hi all
      > I'm looking for a way to find the number of weekdays between 2 dates
      > In my form I have three fields for a begin date (dd)(mm)(yyyy) and
      > three for the end date (dd)(mm)(yyyy)
      > Now these values will be stored into a database and at the same time
      > there will be an e-mail generated and send to me that contains the
      > starting date en the end date . But now I want an extra line in this
      > e-mail that tells me howmany days there are between the starting date
      > en end date so that the e-mail contents looks something like this.
      >
      > Begin date : (dd) (mm) (yyyy)
      > End date : (dd) (mm) (yyyy)
      > Days between (number of days)
      >
      > so lets say
      > starting date is 01/01/2003
      > end date is 15/01/2003
      > then the number of days between should say 11
      > (01-02-03-06-07-08-09-10-13-14-15 /01/2003)
      >
      > I realy hope someone would be so kind to give me a solution on my
      > problem.
      > thx a miljion in advanced.[/color]

      Comment

      Working...