By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,447 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

Number of weekdays between 2 dates.

P: n/a
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.
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Tiernan!

On 4 Sep 2003 01:27:23 -0700, mi*************@bluestripes.be (Tiernan)
wrote:
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)
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.
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)
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.
I realy hope someone would be so kind to give me a solution on my
problem.
thx a miljion in advanced.


you're welcome.

Jochen

--
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 16 '05 #2

P: n/a
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_date) < 6 ) weekdays += 5-weekday(start_date)
if ( day_difference > 7 ) {
weekdays += weekday(end_date)
if ( weekday(end_date) == 6 ) weekdays-- // don't add saturday
}


mi*************@bluestripes.be (Tiernan) wrote in message news:<5c**************************@posting.google. com>...
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.

Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.