Link to home
Start Free TrialLog in
Avatar of jblayney
jblayneyFlag for Canada

asked on

php subtract from date

hello,

I am trying to subtract 2 days from today using this code i found on php.net, but it is giving me error

http://php.net/manual/en/datetime.sub.php

$date = date("Y-m-d");
date_sub($date, date_interval_create_from_date_string('2 days'));
$newdate = date_format($date, 'Y-m-d');

Open in new window


the errors i get are

Warning: date_sub() expects parameter 1 to be DateTime, boolean given in /jb_clear_system.php on line 10

Warning: date_format() expects parameter 1 to be DateTimeInterface, boolean given in /jb_clear_system.php on line 11


I want the date in this format so I can compare it to my mysql entries that are stored the same way.
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial