View Issue Details

IDProjectCategoryView StatusLast Update
0002088XdebugUncategorizedpublic2022-05-11 13:39
ReporterCheveuCodeur Assigned Toderick  
PrioritynormalSeveritycrashReproducibilityhave not tried
Status feedbackResolutionopen 
PlatformwindowsOSWindows 10 FamilleOS Versionx64
Product Version3.1.3 
Summary0002088: problem with date_diff
Description

Xdebug does not take into account the time of a DateTime object when calculating with date_diff, it is able to find a correct answer without having to format the DateTime upstream whereas PHP needs to format it upstream.

Steps To Reproduce

$dateRdv = new DateTime('2022-04-30');
$now = new DateTime('2022-04-28 15:10:33.671060');

//Functional version with Xdebug:
$d=DateTime::createFromFormat('Y-m-d', $dateRdv);
$interval = date_diff($now, $d);
$nbDays=$interval->format('%d');
//$nbDays = 2

//Version with PHP
$d = DateTime::createFromFormat('Y-m-d', $dateRdv);
$interval = date_diff($datenow, $d);
$nbDays = $interval->format('%d');
//$nbDays = 1;

//Functional version with PHP
$d = DateTime::createFromFormat('Y-m-d', $rappel['date_rappel']);
$datenow=Datetime::createFromFormat('Y-m-d',$now->format('Y-m-d'));
$interval = date_diff($datenow, $d);
$nbDays = $interval->format('%d');
//$nbDays = 2;

Tagsphp
Operating System
PHP Version7.3.30-7.3.39

Activities

CheveuCodeur

2022-04-28 13:44

reporter   ~0006282

Sorry i change the second test :

//Version with PHP
$d = DateTime::createFromFormat('Y-m-d', $dateRdv);
$interval = date_diff($now, $d);
$nbDays = $interval->format('%d');
//$nbDays = 1;

derick

2022-04-29 09:21

administrator   ~0006287

Hi,

Your script does not run, and warns and fatals with the following output:

Warning: DateTime::createFromFormat() expects parameter 2 to be string, object given in Standard input code on line 6

Call Stack:
    4.3167     427200   1. {main}() Standard input code:0
    4.3179     429080   2. DateTime::createFromFormat($format = 'Y-m-d', $time = class DateTime { public $date = '2022-04-30 00:00:00.000000'; public $timezone_type = 3; public $timezone = 'UTC' }) Standard input code:6

Warning: date_diff() expects parameter 2 to be DateTimeInterface, bool given in Standard input code on line 7

Call Stack:
    4.3167     427200   1. {main}() Standard input code:0
    4.3180     430168   2. date_diff($object = class DateTime { public $date = '2022-04-28 15:10:33.671060'; public $timezone_type = 3; public $timezone = 'UTC' }, $object2 = FALSE) Standard input code:7

Fatal error: Uncaught Error: Call to a member function format() on bool in Standard input code on line 8

Error: Call to a member function format() on bool in Standard input code on line 8

Call Stack:
    4.3167     427200   1. {main}() Standard input code:0

Please attach a script that I can run without errors, and be very clear where the expected output is different from what you get. Hinting at it with // and some comments is not clear enough for me.

cheers,
Derick

derick

2022-05-11 13:39

administrator   ~0006297

Hi? Would you have the requested information please?

Issue History

Date Modified Username Field Change
2022-04-28 13:41 CheveuCodeur New Issue
2022-04-28 13:41 CheveuCodeur Tag Attached: php
2022-04-28 13:44 CheveuCodeur Note Added: 0006282
2022-04-29 09:21 derick Assigned To => derick
2022-04-29 09:21 derick Status new => feedback
2022-04-29 09:21 derick Note Added: 0006287
2022-05-11 13:39 derick Note Added: 0006297