Re: Previous and Next Month and Year
| From: | Vlad Vlasceanu | Date: | Sun, 17 Jun 2007 06:13:32 +0000 |
| Subject: | Re: Previous and Next Month and Year | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-257204@lists.php.net to get a copy of this message | ||
time() returns a unix timestamp of the current moment in time (now), so in effect you are adding or subtracting 6 seconds to that.
calling:
date('m/d/Y', time());
is the same as calling:
date('m/d/Y');
On the other hand:
mktime(hour, minute, second, month, day, year) generates a timestamp such that:
mktime(0, 0, 0, date('d'), date('m') + 6, date('Y'));
would generate a date timestamp 6 months in the future.
or
mktime(0, 0, 0, 0, date('m'), date('Y'));
would generate last day from last month this year.
Word of wisdom: don't rely solely on timestamp calculations e.g. now + 24 hours and so on, because you may need to take into account daylight savings times and such otherwise your calculations may be off.
Vlad
Keith Spiller wrote:
Hi, RE: Previous and Next Month and Year This is my code: $next_month = date('F Y', time()+$month); $prev_month = date('F Y', time()-$month); echo "$prev_month <br /> \n"; #Result "June 2007" echo "$next_month <br /> \n"; #Result "June 2007" What I am trying to do is get the month and year based upon a + or - $month value. The variable $month being "6" for the month of June of the present year of 2007. For example ($month -7) would be December 2006, and ($month +7) would be January 2006. Please help... Thank you. Keith