Home >Backend Development >PHP Tutorial >Why can't the now() function display the time?
<code> $query = "INSERT INTO class (name,time) VALUES ('$name', NOW())";</code>
Such a sentence. But after submission, there is only date and no time in the phpmyadmin database, and the output looks like this——
<code>tian 2016-11-24 tian 2016-11-23 tian 2016-11-24 tian 2016-11-24 tian 2016-11-24</code>
But you can get the current date and accurate time by executing select now() directly inside. Why can’t it work when submitting?
<code> $query = "INSERT INTO class (name,time) VALUES ('$name', NOW())";</code>
Such a sentence. But after submission, there is only date and no time in the phpmyadmin database, and the output looks like this——
<code>tian 2016-11-24 tian 2016-11-23 tian 2016-11-24 tian 2016-11-24 tian 2016-11-24</code>
But you can get the current date and accurate time by executing select now() directly inside. Why can’t it work when submitting?
Please check whether the time field in your table is set to Datetime. If it is set to Date or char(10), it will be truncated due to incorrect format or length.