Hi Chaps, I have a MySQL (Y-m-d H:i:s) starting date. . . I then have a task duration in seconds/minutes What I'm after is a task 'due' date, which falls between normal working hours (09:00 - 17:30). $task_start = 2010-05-27 16:08:23; $duration = 45000; // Which I guess is 12.5 hours???? $start_str = strtotime($task_start); $calc = $start_str + $duration; $due_date = date('Y-m-d H:i:s', $calc); echo $due_date; // 2010-05-28 04:38:23 PHP: As you can see, the calculation is correct, but the time falls outside the normal working hours, so I need some sort of function to check, then re-calculate so it falls between 09:00-17:30. Any help would be awesome!
i think its the initial time thats your problem, you are getting time from the database but parses and views it in php.. i suggest you also use php in getting the local time then lets see what happens. i too have some problems with the time of db and the apache, its not synchronized.
Hi Bartolay, thanks for the reply . . I thought that's what I'm doing here: Does this not convert the MySQL date to UNIX date format? I'm not having problems with the calculation of the due date, my problem is that I need to check that the $due_date falls between working hours (09:00-17:30), do you know how to do this???
I now have this code, that will calculate the correct times, but does anyone know how I can check to see if the correct time falls on a weekend, and if so, move it to the next Monday? $task_start = "2010-05-27 16:08:23"; $duration = 45000; // Which I guess is 12.5 hours???? $start_str = strtotime($task_start); $calc = $start_str + $duration; $due_date = date('Y-m-d H:i:s',$calc); $test_date=$calc; $test_endtime=strtotime(date("Y-m-d",$start_str )." 17:30"); //start date 17:30 $test_starttime=strtotime(date("Y-m-d",$start_str+3600*24)." 9:00"); //next date 9:00 while ($test_date > $test_endtime) { $diff=$test_date - $test_endtime; $test_date=$test_starttime + $diff; $test_endtime+=3600*24; $test_starttime+=3600*24; } echo "<br>".$due_date; // 2010-05-28 04:38:23 echo "<br>".date('Y-m-d H:i:s',$test_date) //2010-05-29 11:38:23 $task_due = date('Y-m-d H:i:s',$test_date); PHP: