Re: I`m having a little trouble displaying future dates...
| From: | Chris Adams | Date: | Wed, 11 Oct 2000 17:31:44 +0000 |
| Subject: | Re: I`m having a little trouble displaying future dates... | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-3529@lists.php.net to get a copy of this message | ||
> But it only stores as 0000-00-00 00:00:00. I suppose it has something to
do
> with my format.
First, I'd recommend ditching the manual date formatting and using Unix
timestamps (see date()/time() in the PHP manual and the MySQL UNIX_TIMESTAMP
/ FROM_UNIX_TIME functions). Among other things, this makes it very easy to
add times and eliminates the need to spend time worrying about date formats
in your code (on the code I write, Unix timestamps are used everywhere for
storage and calculations; the only place I worry about formats is in the
date() call to display something to the user). It also allows you to things
like $tomorrow = time() + 86400, since you're just manipulating seconds.
On the content management system I wrote, I gave the users 6 fields for the
release date of an article (year / month / day, hour / minute / second),
which sidesteps the whole issue you're experiencing. Alternately, you could
just correct the date using something like
//$ar_timestamp has the user-selected date for the article
$gd = getdate($ar_timestamp);
// Correct to 7AM that day
$corrected_timestamp =
mktime(7,0,0,$gd['mon'],$gd['mday'],$gr['year']);