Page 1 of 1

date(), time(), or mktime()?

Posted: Fri Apr 21, 2006 11:55 pm
by SidewinderX
well ecentially i want to take todays date 4-22-2006 and and add X number of months to it. i was messing around with date(), time(), and mktime() and ive came up with a solution but there has to be an easier way

Code: Select all

<?php
$day = date("d"); //today
$month = date("M"); //this month
$year = date("Y"); //this year
$cycle = "1"; //number of months
$lastday = mktime(0, 0, 0, $month, 0, $year);
$days = strftime("%d", $lastday); //days in this month
$nextMonth = time() + ($cycle * $days * 24 * 60 * 60);
// number of months * days in this month * 24 hours a day * 60 minutes per hour * 60 seconds per minute
echo 'Next Month\'s date is: '. date('Y-m-d', $nextMonth) ."\n";
?>

Posted: Sat Apr 22, 2006 4:05 am
by Oren

Code: Select all

$next_month = strtotime("+1 month")
Check out this: http://us2.php.net/manual/en/function.strtotime.php for more info.