SQL NOW()函数无法正常工作

时间:2021-12-14 21:28:55

I'm trying to insert the date in a a query, using the NOW() statement.

我正在尝试使用NOW()语句在查询中插入日期。

However only the Y-m-d are being inserted correctly, while the hours, minutes and seconds are all appearing zeros ( 00:00:00 )

但是只有正确插入Y-m-d,而小时,分钟和秒都显示为零(00:00:00)

Any reason for that?

有什么理由吗?

2 个解决方案

#1


3  

Did you check the type of the column you are inserting into? Make sure it's datetime, not just date.

您是否检查了要插入的列的类型?确保它是日期时间,而不仅仅是日期。

Refer to the docs for more info.

有关详细信息,请参阅文档。

#2


0  

Try this :

尝试这个 :

SELECT CURRENT_TIMESTAMP
or
SELECT GETDATE()
or
Select {fn NOW()}

SELECT CURRENT_TIMESTAMP或SELECT GETDATE()或选择{fn NOW()}

Note the accolades in the function.

请注意功能中的荣誉。

#1


3  

Did you check the type of the column you are inserting into? Make sure it's datetime, not just date.

您是否检查了要插入的列的类型?确保它是日期时间,而不仅仅是日期。

Refer to the docs for more info.

有关详细信息,请参阅文档。

#2


0  

Try this :

尝试这个 :

SELECT CURRENT_TIMESTAMP
or
SELECT GETDATE()
or
Select {fn NOW()}

SELECT CURRENT_TIMESTAMP或SELECT GETDATE()或选择{fn NOW()}

Note the accolades in the function.

请注意功能中的荣誉。