PHP time

How can I add a second to a date. ex. I have a date 2009-01-14 06:38:18 I need to add -750 seconds to this date and want to get the result in datetime

0
source share
2 answers

You need to convert this date to unix timestamp , where such operations are trivial:

$unix_timestamp = strtotime('2009-01-14 06:38:18'); $new_string = date('Ymd H:i:s', $unix_timestamp - 750); 
+4
source

strtotime () also supports some date / time arithmetic.

 $ts = strtotime('2009-01-14 06:38:18 -750 seconds'); echo date('Ymd H:i:s', $ts); 

or for example

 $ts = strtotime('2009-01-14 06:38:18 next monday'); echo date('Ymd H:i:s', $ts); 
prints 2009-01-19 00:00:00
+2
source

Source: https://habr.com/ru/post/1412071/


All Articles