I am facing with a problem.
When $start
and $end
have the same value, the Days in $intervalo->format("Years:%Y,Months:%M,Days:%d,Hours:%H,Minutes:%i,Seconds:%s")
will return 0.
How can I change this, that if same value (date) the Days = 1.
Thanks for your help!!!
date_default_timezone_set("Europe/Rome");
$start='2021-09-17';
$end='2021-09-17';
$intervalo = date_diff(date_create($start), date_create($end));
echo $intervalo->format("Years:%Y,Months:%M,Days:%d,Hours:%H,Minutes:%i,Seconds:%s");
CodePudding user response:
If you really need it and keeping with the way you're formatting you can simply do:
...
$intervalo->d = $intervalo->days === 0 ? 1 : $intervalo->d;
echo $intervalo->format(...
Check the result type of array_diff
to learn more.