Jump to content

Recommended Posts

Hello

I have some serious date and time problem and i am working on it for 3 days without any hope.

 

On my current job day change at 07:00 and i cannot calculate to see if person working or not if his job end after 00:00

 

My current code work fine if current time until 07:00am but fail after it.

// Find end hour
$working_hour = explode("~", "10:00~01:30");
// Explode it to hour and minute
$ending = explode(":", $working_hour[1]);
$mid = ($working_hour[1] > "07:00" && $working_hour[1] < "23:59") ? 1 : 0;
$end_hour = mktime($ending[0], $ending[1], 0, date("n"), date("d") - $mid, date("Y"));
$current  = mktime(date("H"), date("i"), 0, date("n"), date("d"), date("Y"));
// Return result
if($end_hour < $current)
return "-";
else if($row['left_min'] > 0)
return "You have " .$row['left_min'] ." minutes left";
else
return "you are done";

 

However; yesterday i wrote some code which works perfect for single count but fail in loop.

Here it is;

$array_for_hour = array();
$working_hour = explode("~", "10:00~01:30");
// if job end after midnight
if($working_hour[1] > "23:59" || $working_hour[1] > "00:00")
{
$start_hour = strtotime($working_hour[0]);
$end_hour = strtotime("23:59");
// Add into array every 30 minutes
for($i = $start_hour; $i <= $end_hour; $i += 1800)
{
 $array_for_hour = $i;
}

// Add another 30 minutes to comlete to 00:00
array_push($array_for_hour, $i);


$midnight_start = strtotime("00:30");
$midnight_end = strtotime($working_hour[1]);
// Add hours into array from midnight to actual end hour
for($i = $midnight_start; $i <= $midnight_end; $i += 1800)
{
 $array_for_hour = $i;
}
}
else
{
$start_hour = strtotime($working_hour[0]);
$end_hour = strtotime($this->bitis_saat);

if($end_hour == "00:00")
 $end_hour = "23:59";

for($i = $start_hour; $i <= $end_hour; $i += 1800)
{
 $this->arr[] = $i;
}

if($end_hour == "00:00")
 array_push($array_for_hour, $i);
}

 

Thanks for any help and advise.

 

Regards

Link to comment
https://forums.phpfreaks.com/topic/273890-serious-date-time-problem/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.