Last active
May 4, 2020 23:59
-
-
Save sepehr/6351322 to your computer and use it in GitHub Desktop.
PHP: Get month difference between two timestamps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Calculates how many months is past between two timestamps. | |
* | |
* @param int $start Start timestamp. | |
* @param int $end Optional end timestamp. | |
* | |
* @return int | |
*/ | |
function get_month_diff($start, $end = FALSE) | |
{ | |
$end OR $end = time(); | |
$start = new DateTime("@$start"); | |
$end = new DateTime("@$end"); | |
$diff = $start->diff($end); | |
return $diff->format('%y') * 12 + $diff->format('%m'); | |
} |
Thank you
Good one! Thank you!
The solution is not that elegant, but it´s working, so...
Have a great time!
Thank you So Every Good Every Good Every Good
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good one