RE: [PHP] Date functions
| From: | Craig Vincent | Date: | Mon, 14 Aug 2000 17:59:45 +0000 |
| Subject: | RE: [PHP] Date functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11650@lists.php.net to get a copy of this message | ||
> Perhaps the capability is there and I'm just missing it but I didn't see
> an obvious way to do months. Like finding the last day of the month.
Here's the coding I usually use to do all my date calculations:
1 - list($hour, $min, $sec, $day, $mon, $yr) = explode(" ",date("H i s d m
y"));
2 - $last_month = date('Y-m-d',mktime($hour, $min, $sec, $mon-1, $day,
$yr));
3 - echo $last_month;
Would return 2000-07-14
Line 1 initializes the six(6) date variables that I use, Line 2 calculates
the date I want to find out...the beauty of mktime is that you aren't
restricted in any of the time fields....if you want to know what day it was
three days ago, you could either have it calculated as $day-3 or $hour-72
.... and if you you roll over into another day/month/year/etc... mktime
automatically adjusts all the proper information.
This should solve 95% of all your date calculation needs.
Sincerely,
Craig Vincent
-------------------------
Senior Programmer
Jazzmonkey Media Inc.
http://www.jazzmonkey.com
-------------------------