Rockbottom
12-05-2005, 03:32 PM
Hello,
I am just starting to learn PHP/MySQL and I need to store a date in MySQL for an application that I am writing.
I am wondering what the best way of doing this would be, I thought about using the PHP date(); function and storing it in a varchar field but surely there is a better way? I am using PEAR DB if that makes any difference. :)
Cheers,
Steve. :lovewht:
malenski
12-05-2005, 04:03 PM
I'd use a date type
http://dev.mysql.com/doc/refman/4.1/en/date-and-time-types.html
ubersmith_boo
12-05-2005, 05:12 PM
You can't really go wrong with unix timestamps. There are plenty of very useful php functions that work with them. date() in particular.
adamw111
12-05-2005, 05:21 PM
I always use datetime - if you are inserting the current time then you can use the mysql NOW() function on the insert, saves a lot of bother creating it through php.
malenski
12-05-2005, 05:46 PM
I think U can make the default of a column now() so it doesn't have to be put in the insert().
And if U can't someone will correct me.
dspillettt
12-05-2005, 06:17 PM
I always use datetime - if you are inserting the current time then you can use the mysql NOW() function on the insert, saves a lot of bother creating it through php.
Be sure that you are happy with the timezone set for MySQL (which will either be your host's local timezone of GMT)
Otherwise: use php, where you can better control the timezone used, to generate the dates and insert them. You can use the PHP date formatting strings to put them into a format that will be taken as a date without ambiguity (something like "YYYY-MM-DD HH:MM" should do it)