acctman Posted July 27, 2008 Share Posted July 27, 2008 What's the best Time/Date method to use when storing into a database? Mysql has a TIMESTAMP that will fill into automatically but there is also a time() that you can add during a php sql insert call. any suggestion as to what i should use. right now i'm using the php time() and the entry into the db looks like this 1217123817 Link to comment https://forums.phpfreaks.com/topic/116793-solved-best-timestamp-method-to-use/ Share on other sites More sharing options...
DarkWater Posted July 27, 2008 Share Posted July 27, 2008 I'd use a DATETIME column and use the MySQL function NOW() to fill it. If you need to format it, use DATE_FORMAT(), and if you need to get the timestamp, use UNIX_TIMESTAMP(), all of which are MySQL functions. Link to comment https://forums.phpfreaks.com/topic/116793-solved-best-timestamp-method-to-use/#findComment-600623 Share on other sites More sharing options...
acctman Posted July 27, 2008 Author Share Posted July 27, 2008 i tried using the now() and i'm receiving this error Fatal error: Call to undefined function: now() sql_query("INSERT INTO $logstable VALUES('$line[m_id]','$line[m_user]',".now().",'$ip') ". "ON DUPLICATE KEY UPDATE log_user='$line[m_user]',log_time='".now()."',log_ip='$ip'"); Link to comment https://forums.phpfreaks.com/topic/116793-solved-best-timestamp-method-to-use/#findComment-600629 Share on other sites More sharing options...
DarkWater Posted July 27, 2008 Share Posted July 27, 2008 It's a MySQL function I said. =P Just put it right into the query: INSERT INTO something (datecolumn) VALUES (NOW()) Link to comment https://forums.phpfreaks.com/topic/116793-solved-best-timestamp-method-to-use/#findComment-600632 Share on other sites More sharing options...
acctman Posted July 27, 2008 Author Share Posted July 27, 2008 thanks Link to comment https://forums.phpfreaks.com/topic/116793-solved-best-timestamp-method-to-use/#findComment-600633 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.