Never worked with mysql but I would assume there's something like 'NOW' or
now() or something similar, don't know how you'd put a different date in
though :(

timestamps are handy within php, you can then convert it to whatever format
you want with date()

or, if you wanted to go even further, create a date class and do all your
date manipulation using objects... I've found that easier since I've got a
class already written, but don't know where I've put it now :( so I can't
send it...

Martin

-----Original Message-----
From: Justin French [mailto:[EMAIL PROTECTED]]
Sent: Monday, January 21, 2002 10:43 AM
To: php
Subject: [PHP] best way to approach dates


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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to