Difference between two PHP times as years, months and days for PHP version 5.2
Posted
by
Dominor Novus
on Stack Overflow
See other posts from Stack Overflow
or by Dominor Novus
Published on 2012-10-17T22:59:16Z
Indexed on
2012/10/17
23:00 UTC
Read the original article
Hit count: 187
Forward:
I've scanned through the existing questions/answers on this matter. This is not a duplicitous question; I cannot find a working solution from the accepted answers.
The main questions/answers I've reviewed can be found here: How to calculate the difference between two dates using PHP?
What I need:
A calucalation of the difference between two dates expressed as years, months and days that works with PHP version: 5.2.
<?php
$current_date = date('d-M-Y');
$future_date = '2012-11-01';
?>
What I've tried:
- Most answers I find online don't seem to exact in that they don't factor in leap years.
- This highly rated answer won't work because DateTime->diff() is php 5.3+.
This accepted answer results in (i.e. the second block of code aimed at PHP 5.2) results in the following being parsed:
Array ( [y] => 25 [m] => 11 [d] => 7 [h] => 3 [i] => 15 [s] => 19 [invert] => 0 [days] => 9473 ) Array ( [y] => 25 [m] => 11 [d] => 7 [h] => 3 [i] => 15 [s] => 19 [invert] => 1 [days] => 9473 )
I can't tell if I've incorrectly applied the code or it's simply a case of me not knowing how to manipulate the array.
© Stack Overflow or respective owner