Asked  7 Months ago    Answers:  5   Viewed   26 times

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

Warning: date() expects parameter 2 to be long, string given 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 resolve this?



date() expects a unix timestamp... I imagine you are passing it a date as a string.

e.g. 2010-10-10

You should use:

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

Or better yet, use the DateTime object.

$expiry_date = new DateTime($rows['expiry_date']);
$this->expiry_date = $expiry_date->format('m/d/Y');
Wednesday, March 31, 2021
answered 7 Months ago

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario:

Related usability ticket:

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
answered 7 Months ago

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
answered 5 Months ago

Instead of

$date_parts1=explode($dformat, $beginDate);
$date_parts2=explode($dformat, $endDate);
$start_date=gregoriantojd($date_parts1[0], $date_parts1[1], $date_parts1[2]);
$end_date=gregoriantojd($date_parts2[0], $date_parts2[1], $date_parts2[2]);

try this

$date_parts1=strptime($beginDate, 'dd/mm/YYYY');
$date_parts2=strptime($endDate, 'dd/mm/YYYY');
$start_date=gregoriantojd($date_parts1['tm_mday'], $date_parts1['tm_mon'], $date_parts1['tm_year']);
$end_date=gregoriantojd($date_parts2['tm_mday'], $date_parts2['tm_mon'], $date_parts2['tm_year']);

It's a bit longer, but strptime is specifically for turning formatted date strings into an array of named pieces.

Saturday, May 29, 2021
answered 5 Months ago

The first parameter to date_format needs to be an object of DateTime class.

echo "<td>" . date_format( new DateTime($row['date']), 'd/m/Y H:i:s' ). "</td>";

or, alternatively

echo "<td>" . date_format( date_create($row['date']), 'd/m/Y H:i:s' ). "</td>";
Monday, August 16, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :