Viewed   84 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?

 Answers

5

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');
Sunday, October 30, 2022
5

Here's what worked best for me when trying to script this (in case anyone else comes across this like I did):

$ pecl -d php_suffix=5.6 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.0 install <package>
$ pecl uninstall -r <package>

$ pecl -d php_suffix=7.1 install <package>
$ pecl uninstall -r <package>

The -d php_suffix=<version> piece allows you to set config values at run time vs pre-setting them with pecl config-set. The uninstall -r bit does not actually uninstall it (from the docs):

vagrant@homestead:~$ pecl help uninstall
pecl uninstall [options] [channel/]<package> ...
Uninstalls one or more PEAR packages.  More than one package may be
specified at once.  Prefix with channel name to uninstall from a
channel not in your default channel (pecl.php.net)

Options:
  ...
  -r, --register-only
        do not remove files, only register the packages as not installed
  ...

The uninstall line is necessary otherwise installing it will remove any previously installed version, even if it was for a different PHP version (ex: Installing an extension for PHP 7.0 would remove the 5.6 version if the package was still registered as installed).

Monday, December 12, 2022
4

The constant JSON_PRETTY_PRINT is only available for PHP versions >= 5.4. It's value is 128, so try replacing JSON_PRETTY_PRINT with 128

echo json_encode($categories,128);
Monday, October 17, 2022
 
kvh
 
kvh
4

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.

Tuesday, November 15, 2022
 
4

Never used any of those, but they look interesting..

Take a look at Gearman as well.. more overhead in systems like these but you get other cool stuff :) Guess it depends on your needs ..

Friday, November 11, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share