best way to approach dates
| From: | Justin French | Date: | Sun, 20 Jan 2002 23:42:54 +0000 |
| Subject: | best way to approach dates | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-81297@lists.php.net to get a copy of this message | ||
Hi all,
I'm looking to normalise the way in which I work with dates and times,
hopefully saving myself some time and effort along the way.
Currently, for, say, a news post, i'm using a MySQL DATE column
(YYYY-MM-DD), but since this isn't all that good (visually) for use on a
site, I find myself converting it back out to something like DD-MM-YY or
DD-MM for use on the site. Not exactly hard, but it's gotta be done
every time.
Now I find myself wanting to sort things by date (where the ID might be
in the wrong order... so 2001-12-25 is listed before 2001-12-26, etc),
and more importantly, comparing two dates (3 days away, 3 days ago, 3
hours ago, etc etc).
Would I be better off using a unix timestamp for everything, then using
it to:
- convert to different formats
- compare
- sort in date order
- etc etc
Also, I've noticed there is a timestamp column type in MySQL... is there
a way to cut down on PHP code by using MySQl alone to enter the
timestamp (or date) for me?
Any other suggestions on a sensible method of implementing dates & times
accross many sites and many bits of code?
Justin French