Jump to content


Photo

How to store date in mysql database


  • Please log in to reply
2 replies to this topic

#1 PigsHidePies

PigsHidePies
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 14 September 2006 - 11:03 AM

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

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 14 September 2006 - 11:17 AM

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.
date("D-m-y", $row['timestamp']);


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

#3 PigsHidePies

PigsHidePies
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 14 September 2006 - 11:49 AM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users