Home >Backend Development >PHP Tutorial >Why can't the now() function display the time?

Why can't the now() function display the time?

WBOY
WBOYOriginal
2016-12-01 00:26:023258browse

<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?

Reply content:

<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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn