Thread: Calendar help
View Single Post
Old 10-05-2009, 01:55 PM   #2 (permalink)
ioan1k
The Contributor
 
ioan1k's Avatar
 
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
ioan1k is on a distinguished road
Default

Very simple to do just add or subtract to the current timestamp

When changing months + or - you just add or subtract
(2678400 * (Number of months))

For a year you would + or minus (31556908 * (Number of Years))

The two numbers
2678400 - Is the number of seconds in a day
31556908 - Number of seconds in a year.

For example a year would be

PHP Code:
// its 2009
$timestamp 1254750653;
echo 
date('Y'$timestamp);
echo 
"\n";
// lets go to say... 2012
$yearPlus $timestamp + (31556908 3);
echo 
date('Y'$yearPlus); 
Month

PHP Code:
// its October
$timestamp 1254750653;
echo 
date('M'$timestamp);
echo 
"\n";
// lets go to say... February
$monthPlus $timestamp + (2678400 4);
// its now February!
echo date('Y'$monthPlus); 
You could of course make the month calculations more accurate by using the number of days in each month for every month you advance ... but the most you will be off is +/- 3 days
__________________
My Portfolio - Work - Need freelance Work?
I've been developing 5 years now, and I learn something new everyday
ioan1k is offline  
Reply With Quote