The following is really easy way to add days, minutes, hours and seconds to a time using PHP. Using the date function to set the format of the date to be returned then using strtotime to add the increase or decrease of time then after a comma use another strtotime passing in the start date and time.
//set timezone date_default_timezone_set('GMT'); //set an date and time to work with $start = '2014-06-01 14:00:00'; //display the converted time echo date('Y-m-d H:i',strtotime('+1 hour +20 minutes',strtotime($start)));
Times can be entered in a readable way:
- +1 day = adds 1 day
- +1 hour = adds 1 hour
- +10 minutes = adds 10 minutes
- +10 seconds = adds 10 seconds
To sub-tract time its the same except a - is used instead of a +
For the past 12 years, I’ve been developing applications for the web using mostly PHP. I do this for a living and love what I do as every day there is something new and exciting to learn.
In my spare time, the web development community is a big part of my life. Whether managing online programming groups and blogs or attending a conference, I find keeping involved helps me stay up to date. This is also my chance to give back to the community that helped me get started, a place I am proud to be apart of.
Besides programming I love spending time with friends and family and can often be found together going out catching the latest movie, staying in playing games on the sofa or planning a trip to someplace I’ve never been before.