How to deal with dates in regards to database storage?

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!


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 :-)

    链接地址: http://www.djcxy.com/p/25110.html

    上一篇: 我应该用什么来节省日期和时间

    下一篇: 如何处理关于数据库存储的日期?