jonaHill87 Posted March 17, 2008 Share Posted March 17, 2008 Hi. I'm trying to get the current date/time and then put it in a database for later use(select and display using php). So far I have a var that's gets the date/time: $now = date("Y-m-d"); Then I insert it the database using a simple insert command: INSERT INTO table VALUES('$now'); My field is a DATETIME field. If I select and display the data in this field with php, it displays as 2008-03-17 00:00:00. So it's getting the date but not the time. How can I do this to get the time as well as the date? Thanks to anyone that helps. Link to comment https://forums.phpfreaks.com/topic/96622-format-datetime-for-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 17, 2008 Share Posted March 17, 2008 You are only supplying the date, so the time is filled in with zero's. Do this the easy way and just use the mysql NOW() function in the query - INSERT INTO table VALUES(NOW()); Link to comment https://forums.phpfreaks.com/topic/96622-format-datetime-for-database/#findComment-494458 Share on other sites More sharing options...
eddierosenthal Posted March 18, 2008 Share Posted March 18, 2008 you can use the h m s for hours minutes seconds format for date and time. Link to comment https://forums.phpfreaks.com/topic/96622-format-datetime-for-database/#findComment-494552 Share on other sites More sharing options...
jonaHill87 Posted March 20, 2008 Author Share Posted March 20, 2008 forgot to say thanks guys for the help. The first solution works fine. Didn't try the second but thanks for that one too. Link to comment https://forums.phpfreaks.com/topic/96622-format-datetime-for-database/#findComment-496563 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.