Jethro Hazelhurst Jethro Hazelhurst - 2 months ago 6
MySQL Question

PHP Event booking: get time in increments of 30 minutes is 1 hour out

I am trying to get a select box with a list of time increments from 00:00 to 24:00.

The time increments are an associative array of seconds to the display time like this:

1800 => 00:30

Then when someone selects a date, I plan to convert the date (e.g. 2016/9/16) into seconds and then add the time that they selected on to those seconds to get the date time of their event.

To do this I am generating the time increments like this.

public function getIntervals($start_time = '00:00', $end_time = '24:00', $increments = '30')
{
$today = strtotime(date('Y/m/d', time())); // seconds for 2016/9/16

$seconds_start = strtotime(date('Y/m/d', time()) . ' ' . $start_time) - $today;
$seconds_end = strtotime(date('Y/m/d', time()) . ' ' . $end_time) - $today;

while ($seconds_start < $seconds_end) {
$intervals[$seconds_start] = date("H:i", $seconds_start);
$seconds_start = strtotime('+' . $increments . ' minutes', $seconds_start);
}
return $intervals;
}


However my time intervals are one hour out.

enter image description here

If someone selected '2016/9/17 at 01:00 in the morning' the value in seconds of 01:00 in the morning is '0'.

If I add '0' to strtoseconds('2016/9/17') I am going to get '2016/9/17 at 00:00'.

So here I am,one hour out. I assume this is due to my server time being set to paris +1hr, but I have no idea how to fix it.

Answer
$timediff = 3600;

$paris_00_time = strtotime(date('Y-m-d '.'00:00'));

$paris_selected_time = $paris_00_time+1800;

$my_time = date('Y-m-d H:i:s',$paris_selected_time-$timediff);

print_r($my_time);

you can declare $timediff=3600; ( 1 hour )

$paris_00_time = strtotime(date('Y-m-d '.'00:00'));

after someone choose the date ( ex: [1800] => 00:30 ) and is submitted you can process the date

$paris_selected_time = $paris_00_time+1800;

$my_time = date('Y-m-d H:i:s',$paris_selected_time-$timediff);

output: 2016-09-15 23:30:00