PHP Time

Hi Guys

Im writing a small site where users can use a php form to request a time slot so they type in what ever time slot and fill in all the information needed, it then gets inputted into a sql database no problems with all that I then can view the data in a table and I am then creating a sheet where it inputs the data onto a form.

What I need is im pulling the data for the time slot requested and placing it where I need it no problem but then what I would like to do is add 1 Hour onto this time and echo that new time next to the original time. So for example the user requests a 20:00Z time that gets placed into the on station time slot then the off station input needs to show 21:00Z.

I have tried a couple of bits like

[php]<?php
$finaltime = $time=strtotime("+1 hour");
echo $finaltime; ?>[/php]

The original time is $time variable and the +1 hour time needs to be $finaltime

This has got me stuck any help I would be most grateful

Thanks

[php]$dateTime = new DateTime($_POST[‘time’]);

$dateTime->format(‘H:ie’); // 20:00Z

$interval = DateInterval::createfromdatestring(’+1 hour’);
$dateTime->add($interval);

$dateTime->format(‘H:ie’); // 21:00Z[/php]

http://php.net/manual/en/datetime.format.php
http://php.net/manual/en/function.date.php

Hi Thanks I got it sorted in the end I used the following:

[php]echo date(“H:i:s”, strtotime($time.’ +1 hour’));[/php]

[php]$dateTime = new DateTime($_POST[‘time’]);
echo $dateTime->format(‘H:ie’) . “
\n”;
$dateTime->modify(’+1 hour’);
echo $dateTime->format(‘H:ie’);[/php]
:wink:

I knew that felt wrong! Been working with carbon exclusively for way too long ^^

Sponsor our Newsletter | Privacy Policy | Terms of Service