Created
March 3, 2011 08:13
-
-
Save johnfuller/852493 to your computer and use it in GitHub Desktop.
Helpful functions to figure out future dates to days, months, years. Stolen from PHP.net comments for mktime.
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 | |
public function addMonthToDate($timeStamp, $totalMonths=1){ | |
// You can add as many months as you want. mktime will accumulate to the next year. | |
$thePHPDate = getdate($timeStamp); // Covert to Array | |
$thePHPDate['mon'] = $thePHPDate['mon']+$totalMonths; // Add to Month | |
$timeStamp = mktime($thePHPDate['hours'], $thePHPDate['minutes'], $thePHPDate['seconds'], $thePHPDate['mon'], $thePHPDate['mday'], $thePHPDate['year']); // Convert back to timestamp | |
return $timeStamp; | |
} | |
public function addDayToDate($timeStamp, $totalDays=1){ | |
// You can add as many days as you want. mktime will accumulate to the next month / year. | |
$thePHPDate = getdate($timeStamp); | |
$thePHPDate['mday'] = $thePHPDate['mday']+$totalDays; | |
$timeStamp = mktime($thePHPDate['hours'], $thePHPDate['minutes'], $thePHPDate['seconds'], $thePHPDate['mon'], $thePHPDate['mday'], $thePHPDate['year']); | |
return $timeStamp; | |
} | |
public function addYearToDate($timeStamp, $totalYears=1){ | |
$thePHPDate = getdate($timeStamp); | |
$thePHPDate['year'] = $thePHPDate['year']+$totalYears; | |
$timeStamp = mktime($thePHPDate['hours'], $thePHPDate['minutes'], $thePHPDate['seconds'], $thePHPDate['mon'], $thePHPDate['mday'], $thePHPDate['year']); | |
return $timeStamp; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment