jblayney
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
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.
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');
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Procedural
https://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL-Procedural-Version.html
Object-oriented
https://www.experts-exchange.com/articles/20920/Handling-Time-and-Date-in-PHP-and-MySQL-OOP-Version.html