开发者

How to deal with dates in regards to database storage? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

datetime vs timestamp?

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

Do you take a timestamp开发者_StackOverflow中文版 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 :-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜