473,394 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Days calc

hi,

i have the following:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo"test";
  3. //The function returns the no. of business days between two dates and it skips the holidays
  4. function getWorkingDaysTOT($startDate2,$endDate2,$HOLS){
  5.     //The total number of days between the two dates. We compute the no. of seconds and divide it to 60*60*24
  6.     //We add one to inlude both dates in the interval.
  7.     $days2 = (strtotime($endDate2) - strtotime($startDate2)) / 86400+1; //used for calculating elapsed bus. days
  8.  
  9.     $no_full_weeks2 = floor($days2 / 7);
  10.     $no_remaining_days2 = fmod($days2, 7);
  11.  
  12.  
  13.     //It will return 1 if it's Monday,.. ,7 for Sunday
  14.     $the_first_day_of_week2 = date("N",strtotime($startDate2));
  15.     $the_last_day_of_week2 = date("N",strtotime($endDate2));
  16.  
  17.     //---->The two can be equal in leap years when february has 29 days, the equal sign is added here
  18.     //In the first case the whole interval is within a week, in the second case the interval falls in two weeks.
  19.     if ($the_first_day_of_week2 <= $the_last_day_of_week2){
  20.         if ($the_first_day_of_week2 <= 6 && 6 <= $the_last_day_of_week2) $no_remaining_days2--;
  21.         if ($the_first_day_of_week2 <= 7 && 7 <= $the_last_day_of_week2) $no_remaining_days2--;
  22.     }
  23.     else{
  24.         if ($the_first_day_of_week2 <= 6) {
  25.         //In the case when the interval falls in two weeks, there will be a Sunday for sure
  26.             $no_remaining_days2--;
  27.         }
  28.     }
  29.  
  30.     //The no. of business days is: (number of weeks between the two dates) * (5 working days) + the remainder
  31. //---->february in none leap years gave a remainder of 0 but still calculated weekends between first and last day, this is one way to fix it
  32.    $workingDays2 = $no_full_weeks2 * 5;
  33.     if ($no_remaining_days2 > 0 )
  34.     {
  35.       $workingDays2 += $no_remaining_days2;
  36.     }
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.     //We subtract the holidays
  45.     foreach($HOLS as $HOL){
  46.         $time_stamp2=strtotime($HOL);
  47.         //If the holiday doesn't fall in weekend
  48.         if (strtotime($startDate2) <= $time_stamp2 && $time_stamp2 <= strtotime($endDate2) && date("N",$time_stamp2) != 6 && date("N",$time_stamp2) != 7)
  49.             $workingDays2--;
  50.     }
  51.  
  52.     return $workingDays2;
  53.  
  54. }
  55.  
  56. ?>
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. <?php
  67.   $c = 1;
  68.   //get timestamp for past/future date I want
  69.   $pf_time2 = strtotime("-".$c." day");
  70.   //format the date using the timestamp generated
  71.   $previous_day2 = date("d M Y", $pf_time2);
  72. ?>
  73.  
  74.  
  75.  
  76.  
  77. <?php
  78. $HOLS=array("25 Dec 2008","26 Dec 2008","16 Feb 2009");
  79.  
  80. echo getWorkingDaysTOT("2009-02-15","2009-02-21",$HOLS);
  81.  
  82. $days_in_month2 = date("t"); 
  83. $elapsed_business_days2 =  getWorkingDaysTOT(date("1 M Y"),$previous_day2,$HOLS); //gets the number of working days elapsed in the current month minus any holidays
  84. $business_days2 = getWorkingDaysTOT(date("1 M Y"),date("$days_in_month2 M Y"),$HOLS);
  85.  
  86.  
  87.  
  88. echo "<br>";
  89. echo "business days:";
  90. echo $business_days2;
  91.  
  92.  
  93. ?>
  94.  
for some reason it only works right if i restart the apache server. for example, before i restart the server i am getting 18 for business days. after i restart it i am getting 19 business days. 19 is the correct number. can someone tell me why this is happening, and how i can maybe simulate restarting server or something?

thanks in advance,
geebee
Feb 19 '09 #1
0 1878

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Astra | last post by:
Hi All Wonder if you can help me with the following calc, which I want to create to check whether or not a user has entered a valid credit card expiry date: 1) I have retrieve a value from 2 x...
12
by: Susan Cranford | last post by:
Please forgive, I have looked at so much info I can't figure out how to put it together even though I know it must be fairly simple. I have an array of input text boxes (txtDOBn) where n is...
16
by: PeteCresswell | last post by:
I was happily coding along, putting some calculation results (rolling annualized rates of return - too compute-intensive to calculate on-the-fly - had tb staged beforehand via a batch job) into...
2
by: Sven K?hne | last post by:
Hello *, Our new compiler has some problems with this line: pBuf = Calc(pBuf, i); The Assembler-Code generated uses the increases "i" as a Paramter in Calc. Our old Compiler did not do...
0
by: MLH | last post by:
I was wondering what the differences in resource requirements between calc.exe and notepad.exe might be and if such differences might explain why Access 97 locks up when I run...
6
by: vj | last post by:
I have a program which generates xml files for excel but these files are not recognized by open office calc. I looked at the OO uno library, but it seems like an over kill. In my experience, for...
2
by: tasmontique | last post by:
I am working on an access 2002 flight schedule database. I am new to access but have some basic understanding of sql and vb6 code. I have learned a lot from this website. Thanks much Hopefully...
7
by: sparks | last post by:
I am working on a database that has a lot of calculated values on the forms. These were never put into the tables. But were tied to unbound fields on the forms. Now 8000 records later they want...
1
by: chevyas123 | last post by:
How do i write a function to calculate business days excluding weekends and holidays in oracle? Actually i need to prepare a calendar for my monthly activities i.e activity x to be performed on 3rd...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.