Home > Enterprise >  Passing null to parameter #1 ($datetime) of type string is deprecated in CodeIgniter 4 (PHP 8)
Passing null to parameter #1 ($datetime) of type string is deprecated in CodeIgniter 4 (PHP 8)

Time:09-22

I'm trying to make date difference (in days) between today and a date from a field in database (array), this is my code :

$date1 = date_create ($v['sipp_ed']);//this is from field in database
$date2 = new DateTime();
$intval = date_diff ($date1, $date2);
echo $intval->format("Diiference is %a days"); 

but always get error "Passing null to parameter #1 ($datetime) of type string is deprecated". I have tried many times with other functions like strtotime, date, and getdate, but always fail.....could anybody help me, please ?

CodePudding user response:

On this line

$date1 = date_create ($v['sipp_ed']);

It's telling you that $v['sipp_ed'] is null.

Either check its value or use something like this which will pass an empty string when the value is null.

$date1 = date_create ($v['sipp_ed'] ?? '');
  • Related