Page 1 of 1
Need help Php time coding
Posted: Wed Nov 30, 2016 3:11 am
by php75
Hi everbody,
Once i enter time details in Html form and then click submit button to display add 1 hour to time including seconds.How can i do it by using php code?
Re: Need help Php time coding
Posted: Wed Nov 30, 2016 6:52 am
by Celauran
You need to parse the form input and then add an hour. Look at the DateTime class.
Re: Need help Php time coding
Posted: Wed Nov 30, 2016 5:12 pm
by Christopher
With the PHP DateTime class, you can do something like this:
Code: Select all
$datetime = '2016-12-01 12:34:56';
$date = new DateTime("$datetime + 1 hour");
echo $date->format('Y-m-d H:i:s');
Re: Need help Php time coding
Posted: Wed Nov 30, 2016 9:48 pm
by php75
Hi,
Thank you for ur reply.Actually, I want to set the time first manually and then display add 1 hour to time after submit the button using html form and php.Could u please give me a code for this one?
Re: Need help Php time coding
Posted: Wed Nov 30, 2016 11:46 pm
by Christopher
php75 wrote:Hi,
Thank you for ur reply.Actually, I want to set the time first manually and then display add 1 hour to time after submit the button using html form and php.Could u please give me a code for this one?
I gave you code that you can change a little to do exactly what you want. Just set your date/time.