PHP Salt


A little dash of PHP... my collection of php functions

Version: 2.33.2
Last Build: December 29, 2023 20:28pm (PST)

Main Menu

Home

Get PHP Salt


The Functions

array
db
file
graph
html
mail
math
misc
mobile
script
string
system
time
web
psDateMonths()
Returns number of months bewteen dates


Description:

This will return number of months between dates



Usage:

$months = psDateMonths($start, $end)
$start is first Date, example: 09/02/2011
$end is second Date, example: 12/32/2011



Example:







Code:

function psDateMonths($start, $end)
{
$tsStart = strtotime($start);
$tsEnd = strtotime($end);
$start = date("Y-m-d",$tsStart);
$end = date("Y-m-d",$tsEnd);

$startParsed = date_parse_from_format('Y-m-d', $start);
$startMonth = $startParsed['month'];
$startYear = $startParsed['year'];

$endParsed = date_parse_from_format('Y-m-d', $end);
$endMonth = $endParsed['month'];
$endYear = $endParsed['year'];

$res = ($endYear - $startYear) * 12 + ($endMonth - $startMonth) + 1;
return $res;
}


Changlelog:

Source reference: http://stackoverflow.com/questions/3474469/calculating-amount-of-months-between-dates
Minor change to allow dates in most any format.


See Also

And a shot out to:

PHP - php.net
Fedora Server - getfedora.com
Shameless ads to pay for site