date - PHP days difference -
hello i'm trying make php script compares date 1 of database records , todays date, if difference in days greater 3, come out true.
example:
$todays_date = date("y-m-d"); <-- todays date $deal_date = $data["deal date"]; <-- date database $interval = date_diff($todays_date, $deal_date); <--difference if($interval >= 3) { (something) }
but every time try error "date_diff() expects parameter 1 datetime, string given" know use date_diff both arguments have datetime, i'm not sure how today's date in date , how convert date database datetime.
correct syntax is:
<?php $datetime1 = date_create('now'); $datetime2 = date_create($data["deal date"];); $interval = date_diff($datetime1, $datetime2); $diff = $interval->format('%a'); if($diff >= 3) { (something) } ?>
Comments
Post a Comment