Jump to content

Archived

This topic is now archived and is closed to further replies.

PigsHidePies

How to store date in mysql database

Recommended Posts

Can I use the basic date() function and just put the value in a mysql database? I read that php and mysql interpret dates differently...also, how many chars should the database be...8? Thanks for any help

Share this post


Link to post
Share on other sites
When I deal with dates I prefer to use a unix timestamp (number secounds since Jan 1st 1970), I grab the timestamp using the time() function, then use an INT value and give it a max length of 20 or so.

When I retrieve the date I use the date function to convert the timestamp into a readable date, using the secound parameter of the date functions.
[code=php:0]date("D-m-y", $row['timestamp']);[/code]


If you wnat to use the date function, then you'll wenat to use a VARCHAR field set to 255 chars.

Share this post


Link to post
Share on other sites
Thanks for the help, I used a char field of 24 chars and saved it in date('F jS Y') format...out of curiousity..why should it be 255 chars long?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.