My question is: I have two dates in string format:
string(10) "2016-21-10"
string(10) "2016-05-10"
I can not figure out how to compare them. So basically i need the difference between the two given date. How can I achieve it?
My question is: I have two dates in string format:
string(10) "2016-21-10"
string(10) "2016-05-10"
I can not figure out how to compare them. So basically i need the difference between the two given date. How can I achieve it?
You can use createFromFormat() function to create DateTime object from string.
Create two DateTime object like this,
$date1 = DateTime::createFromFormat('Y-d-m', '2016-21-10');
$date2 = DateTime::createFromFormat('Y-d-m', '2016-05-10');
To get the difference between two dates you can use diff() function. Use it like this,
$interval = $date1->diff($date2);
You can use the $interval
variable to get the difference between two dates.