How can I add second(s) in a date time. ex. I have date time 2009-01-14 06:38:18 I need to add -750 seconds in that date and want result in datetime
strtotime() also supports some date/time arithmetic.
$ts = strtotime('2009-01-14 06:38:18 -750 seconds');
echo date('Y-m-d H:i:s', $ts);
or e.g.
$ts = strtotime('2009-01-14 06:38:18 next monday');
echo date('Y-m-d H:i:s', $ts);
prints 2009-01-19 00:00:00
You need to convert that date to a unix timestamp, where such operations are trivial:
$unix_timestamp = strtotime('2009-01-14 06:38:18');
$new_string = date('Y-m-d H:i:s', $unix_timestamp - 750);