5

Possible Duplicate:
datetime vs timestamp?

I would like to know how best to store dates in the database.

Do you take a timestamp in the code and save it in an INT field. Do you take a date and format it to correct format and store it in a DATETIME field?

What are advantages one way or another? Any good places to read up on the subject?

Thanks for you input!

Community
  • 1
  • 1
Roeland
  • 3,698
  • 7
  • 46
  • 62

1 Answers1

2

I would save the date in a datetime field for the following reasons :

  • If you happen to work directly on the database (debugging or so) you see dates in a readable format, and you can change values with no manual calculation
  • You have date/time functions built in the database that make queries easier to create
  • The code will probably be easier to create/maintain (you let others do the work : ie the database)
  • If you have to migrate your system to another language/framework/os later, your dates will still be OK, but are you sure that, for a given date, a C# timestamp is the same as a PHP timestamp ?
  • What's happening if you move your server to a different time zone ?
  • etc..

Many reason I prefer not to handle this myself, and let the clever people do it :-)

Sébastien Nussbaumer
  • 6,202
  • 5
  • 40
  • 58