Need help Php time coding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php75
Forum Newbie
Posts: 8
Joined: Wed Nov 30, 2016 3:04 am

Need help Php time coding

Post 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?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need help Php time coding

Post by Celauran »

You need to parse the form input and then add an hour. Look at the DateTime class.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need help Php time coding

Post 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');
(#10850)
php75
Forum Newbie
Posts: 8
Joined: Wed Nov 30, 2016 3:04 am

Re: Need help Php time coding

Post 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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Need help Php time coding

Post 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.
(#10850)
Post Reply