Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: What are these Date (diff?) format parameters (eg. %R%a)

Tags:

php

datetime

I runned into few examples where people share code for calculating the difference between two days.

Eg.

$now = new DateTime();
$itemDate->diff($now)->format("%r%a")

But almost always these types of posts don't really have an explanation about what format parameters are about. I'm okay with regular Date format parameters but (as in this case) not sure about eg. %r.

like image 544
eja Avatar asked Dec 18 '22 00:12

eja


1 Answers

When doing difference between DateTimeInterface objects, DateInterval object will be returned. You don't have DateTime's anymore, you have interval, and intervals are formatted different as DateTime objects. Format is explained here: http://php.net/manual/en/dateinterval.format.php

enter image description here

like image 80
Glavić Avatar answered Dec 20 '22 14:12

Glavić