Skip to content

Instantly share code, notes, and snippets.

@sepehr
Last active May 4, 2020 23:59
Show Gist options
  • Select an option

  • Save sepehr/6351322 to your computer and use it in GitHub Desktop.

Select an option

Save sepehr/6351322 to your computer and use it in GitHub Desktop.
PHP: Get month difference between two timestamps
<?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');
}
@JoshyFrancis

Copy link
Copy Markdown

Thank you

@MrzJkl

MrzJkl commented Jul 18, 2018

Copy link
Copy Markdown

Good one! Thank you!
The solution is not that elegant, but it´s working, so...
Have a great time!

@chaisoftsnet

Copy link
Copy Markdown

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