mysql - PHP date minus X days -
i have code in php:
date('y-m-d', strtotime("-7 days")) which using in sql query:
$sql="select * billing_invoices due_date <= '".date('y-m-d', strtotime("-7 days"))."' , (status = 'unpaid' or status = 'part paid') , statement = '0000-00-00 00:00:00' group customer_sequence "; so if date 2014-12-16 show 2014-12-09
i want able run query too:
$sql="select * billing_invoices due_date <= '".date($_post["date"], strtotime("-7 days"))."' , (status = 'unpaid' or status = 'part paid') , statement = '0000-00-00 00:00:00' group customer_sequence "; but date being returned current day rather -7 days posted date
according php manual strtotime there second parameter can specify timestamp wich used instead of current time
int strtotime ( string $time [, int $now ] ) so code should this:
date("y-m-d", strtotime("-7 days", $_post["date"])) perhaps have convert date timestamp before. dependent on date format in $_post["date"] may work:
date("y-m-d", strtotime("-7 days", strtotime($_post["date"])))
Comments
Post a Comment