Yes, use
$userDate = strtotime('2017-08-02 12:00:00');
echo date('Y-m-d H:i:s', strtotime('+4 hours', $userDate));
to get date after 4 hours
Example
Explanation
strtotime
converts about any English textual datetime description into a Unix timestamp. Most commonly it's used with actual date string or with difference string. E.g. +5 months
, 'next Monday' and so on. It will return Unix timestamp - integer that represents how much seconds there is after 1970-01-01 (1970-01-01 00:00:00 is 0, 1970-01-01 00:01:00 is 60 and so on).
So in strtotime('2017-08-02 12:00:00')
we convert date to integer for later use.
strtotime('+4 hours', $userDate)
- here we use our date as "now" parameter (by default it's time()
) and requesting to return timestamp after 4 hours.
echo date('Y-m-d H:i:s', ...);
- date
accepts format and Unix timestamp to convert from integer back to human readable text.