Displaying dates
| From: | Justin French | Date: | Thu, 25 Apr 2002 12:08:00 +0000 |
| Subject: | Displaying dates | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-94538@lists.php.net to get a copy of this message | ||
I strongly recommend reading the date section of the manual... it takes all
of 5 minutes, and you would have come across strtodate():
http://www.php.net/manual/en/function.strtotime.php
... which can accept almost any English date/time phrase (like "next
month"), and convert it to a Unix time stamp... combined with date()'s
ability to accept a given timestamp (as well as the current time), you get
exactly what you want in three lines :)
<?
$today = date("j-M-Y H:i");
$next_month = date("j-M-Y H:i",strtotime("next month"));
$last_month = date("j-M-Y H:i",strtotime("last month"));
echo "Last Month: $last_month <BR>";
echo "Today: $today <BR>";
echo "Next Month: $next_month <BR>";
?>
It gets a little more complex when you're not dealing with the current
server time I think... but that wasn't your question.
Justin French
--------------------
Creative Director
http://Indent.com.au
--------------------
on 25/04/02 8:46 PM, Craig (craig@sitedesign.net) wrote:
> How can i display a dynamic page showing last month and next month and the
> month before
>
> eg
> this moth is <?php echo date("j-M-Y H:i"); ?>
> how do i add 1 to the month or -1 to the month?
>
>