note 88968 added to function.mktime
| From: | admin at stipe dot info | Date: | Mon, 16 Feb 2009 10:12:30 +0000 |
| Subject: | note 88968 added to function.mktime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-150719@lists.php.net to get a copy of this message | ||
With combination of mktime and getDate and date() you can add hours / seconds / days / months /
years to ANY timestamp. Use strtotime() function to convert any type of dates to timestamp
<?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;
}
?>
----
Server IP: 117.104.160.194
Probable Submitter: 220.233.210.145
----
Manual Page -- http://www.php.net/manual/en/function.mktime.php
Edit -- https://master.php.net/note/edit/88968
Del: integrated -- https://master.php.net/note/delete/88968/integrated
Del: useless -- https://master.php.net/note/delete/88968/useless
Del: bad code -- https://master.php.net/note/delete/88968/bad+code
Del: spam -- https://master.php.net/note/delete/88968/spam
Del: non-english -- https://master.php.net/note/delete/88968/non-english
Del: in docs -- https://master.php.net/note/delete/88968/in+docs
Del: other reasons-- https://master.php.net/note/delete/88968
Reject -- https://master.php.net/note/reject/88968
Search -- https://master.php.net/manage/user-notes.php