How to add 24 hours to current timestamp in php
I would like to add 24 hours to the timestamp for now. How do I find the unix timestamp number for 24 hours so I can add it to the timestamp for right now? Show I also would like to know how to add 48 hours or multiple days to the current timestamp. How can I go best about doing this? asked Mar 25, 2010 at 11:37
zeckdudezeckdude 15.3k42 gold badges134 silver badges183 bronze badges 3 You probably want to add one day rather than 24 hours. Not all days have 24 hours due to (among other circumstances) daylight saving time:
answered Mar 25, 2010 at 11:41
Álvaro GonzálezÁlvaro González 137k38 gold badges254 silver badges341 bronze badges 2 A Unix timestamp is simply the number of seconds since January the first 1970, so to add 24 hours to a Unix timestamp we just add the number of seconds in 24 hours. (24 * 60 *60)
answered Mar 25, 2010 at 11:39
1 Add
Hassaan 6,8585 gold badges29 silver badges48 bronze badges answered Mar 25, 2010 at 11:38
Soufiane HassouSoufiane Hassou 16.8k2 gold badges39 silver badges74 bronze badges 1 Unix timestamp is in seconds, so simply add the corresponding number of seconds to the timestamp:
answered Mar 25, 2010 at 11:39
reko_treko_t 54.2k10 gold badges85 silver badges77 bronze badges 1 You could use the DateTime class as well:
Add a Period of 1 Day:
See DateInterval for more details.
answered Mar 25, 2010 at 11:49
SeanJASeanJA 9,9885 gold badges31 silver badges42 bronze badges 0 As you have said if you want to add 24 hours to the timestamp for right now then simply you can do:
Above code will add 1 day or 24 hours to your current timestamp. in place of examples from the manual are as below:
answered Dec 10, 2018 at 6:48
Dharman♦ 27.8k21 gold badges75 silver badges127 bronze badges answered Feb 13, 2020 at 11:24
How much is a day in timestamp?1 Day: 86,400 seconds.
How does PHP calculate 24 hours?php $starttime = strtotime('2017-05-11 21:00:00'); $starttimeformat = date('Y-m-d H:i:s', $starttime); echo "Current Time:"; echo $starttimeformat; echo '
'; echo ' '; $onedayadedtime_format = date('Y-m-d H:i:s', strtotime('+24 hours', $starttime)); echo "End Time after adding 24 hours:"; echo $ ... How do you add hours on Strtotime?You can use DateTime::modify to add time, but I would just do time()+10800 . Show activity on this post. $time = new DateTime("+ 3 hour"); $timestamp = $time->format('Y-M-d h:i:s a');
How can I timestamp in PHP?The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
|