Warning: date () expects parameter 2 to be long, the string is specified in

I keep getting this error on the car_detail.php page in my database

Warning: date () expects parameter 2 to be long, the line is in / home / speedycm / public _html / speedyautos / cars_class.php on line 228 *

cars_class.php reads this on line 228

$this->expiry_date = date("m/d/Y", $rows['expiry_date']);

how can i solve this?

+3
source share
2 answers

date () expects a unix timestamp ... I think you pass it a date as a string.

eg. 2010-10-10

You should use:

$this->expiry_date = date("m/d/Y", strtotime($rows['expiry_date']));

Or better yet, use a DateTime object .

$expiry_date = new DateTime($rows['expiry_date']);
$this->expiry_date = $expiry_date->format('m/d/Y');
+12
source

most databases currently return datestring like this "2011-03-11 20:00:00".

( ):

$this->expiry_date = date("m/d/Y", strtotime($rows['expiry_date']));
+2

All Articles