user1904273 user1904273 - 1 year ago 165
PHP Question

PHP: Alternative to DateTime

I cannot use DateTime because of the version of PHP I am running. Can anyone suggest a way to get the equivalent value using strToTime or some other date function. I know this is probably an easy question but I am very rusty on dates in php.

i.e. something like

$date = strToTime('today');

where $date is a date that I can then manipulate by adding hours and so forth along these lines...

$start = $date->format('Y-m-d H:i:s');
$date->modify('+ 60 minutes');
$end = $date->format('Y-m-d H:i:s');

Thanks in advance for any suggestions.

Answer Source
$startTime = strtotime('now');
$endTime = strtotime('+60 minutes', $startTime);

$start = date('Y-m-d H:i:s', $startTime);
$end = date('Y-m-d H:i:s', $endTime);

You can pass a 2nd parameter to strtotime that will be the time that is used when the calculation is made. By default it is time().


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download