HCProfessionals Posted April 9, 2011 Share Posted April 9, 2011 I am building a new web app and want to make sure I do everything right from the beginning. What is the best method of storing the date and time into a database using PHP along with the table field settings? Quote Link to comment https://forums.phpfreaks.com/topic/233219-best-method-of-storing-date-and-time-into-databse/ Share on other sites More sharing options...
gizmola Posted April 9, 2011 Share Posted April 9, 2011 Read this article first. http://www.gizmola.com/blog/archives/93-Too-much-information-about-the-MySQL-TIMESTAMP.html We really need more information to best answer this question. In particular, what is the range of these date/time values. What will you be doing with them? Are they arbitrary date/time's that the user enters in some fashion through the UI, or automatically set (timestamped) by the system. Quote Link to comment https://forums.phpfreaks.com/topic/233219-best-method-of-storing-date-and-time-into-databse/#findComment-1199390 Share on other sites More sharing options...
coupe-r Posted April 9, 2011 Share Posted April 9, 2011 I do the following DB - created_on DATETIME PHP - date("Y-m-d H:i:s") Quote Link to comment https://forums.phpfreaks.com/topic/233219-best-method-of-storing-date-and-time-into-databse/#findComment-1199395 Share on other sites More sharing options...
Eiolon Posted April 9, 2011 Share Posted April 9, 2011 I typically use DATETIME when I just need to log a date or do some minor calculations. Anything complex, I like to leave the calculations out of the SQL statement and let PHP handle it so I'll use timestamp. But that has been rare for me. Quote Link to comment https://forums.phpfreaks.com/topic/233219-best-method-of-storing-date-and-time-into-databse/#findComment-1199414 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.