|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
week days between 2 dates
i searched this forum for an answer and i found several topics similar to this one, but to be onest with you, they dont work, or they're made for weekends.
can you help me, please, as my project is standing still for 1 week now? how DO you get the numbar of working days between 2 dates? ps:working days in a week are from Monday to Friday(no=5) thx for the interest |
|
#2
|
||||
|
||||
|
here, give this a try.
PHP Code:
Last edited by roninblade : August 11th, 2005 at 04:54 AM. |
|
#3
|
|||
|
|||
|
For the above to really work, you'd have to add tests to make sure the month and the year increase as you get later in date and also so you don't increase the days past the last day of the month. another way would be to do something like:
PHP Code:
|
|
#4
|
||||
|
||||
|
did you at least try the code? the month and year increments is already taken care of by mktime in this line ...
PHP Code:
you're only doing it longer. no need to modify the code ![]() |
|
#5
|
|||
|
|||
|
didn't try the code. As I understood it, you are only increasing the day. I'm not sure how mktime acts when the days get higher than the number of days in the month. If it moves to the first day in the next month, then I've learned something new!
|
|
#6
|
|||
|
|||
|
ok, I've tried it out. You're absolutely right.
|
|
#7
|
|||
|
|||
|
roninblade is right. (as in the manual)
i was working with a 'for' syntax to go day by day from date1 to date2, also using mktime to leap from one day to other, but for some reason didnt seem to act the right way. i tried this script and seems to block my pc for some reason. i entered: $cur_date = $date1 = '2005-08-11'; $date2 = '2006-08-27'; and gave me this: Maximum execution time of 30 seconds exceeded in...... for this line: $day = date('w', mktime(0,0,0,$d[1],$d[2],$d[0])); |
|
#8
|
||||
|
||||
|
errr... maybe you didn't advance the date by one and got caught in an endless loop so the script timed out.
|
|
#9
|
|||
|
|||
|
have any ideea why? i mean...i used your code and is perfect for dates like several months apart, but breakes when you try more then 11 months.
![]() |
|
#10
|
|||
|
|||
|
this is the right way to do it.
PHP Code:
thx guys for your time. result found on: http://ro.php.net/manual/en/function.date.php |
|
#11
|
||||
|
||||
|
Quote:
dont know why its doing that for you but i tried two dates several years apart and it worked fine here. |
|
#12
|
|||
|
|||
|
Hmmm ... the version you posted seems a bit confusing to me xilviu, and I don't like the use of floor() ... although it does seem to work.
Here's how I would write it PHP Code:
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > PHP Development > week days between 2 dates |