簡體   English   中英

Mysql:設置日期=今天的日期

[英]Mysql: Setting date = todays date

我想將DateOfLastupdate設置為今天的日期。

update Products set DateOfLastupdate = (SELECT date(now());

但這不起作用。但是

SELECT date(now()); 

我可以將當​​前日期設置為DateOflastupdate嗎?

你有沒有嘗試過

update Products set DateOfLastupdate = CURDATE();  /* Date part only */

或者如果您想要日期和時間

update Products set DateOfLastupdate = NOW();  /* Date and time */

使用current_date()如果你只需要日期部分,否則使用current_timestamp()或者now()

update Products set DateOfLastupdate = current_date();

嘗試使用此方法。Curdate僅返回當前日期。 或更多使用此http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_curdate

update Products set DateOfLastupdate = CURDATE();

您實際上並不需要進行選擇,如果使用,它會容易得多:

UPDATE products set DateOfLastUpdate = now();

請注意,now()函數是整個日期,包括小時,分鍾和秒。 如果您只想輸入日期,請​​考慮制作一個子字符串。

http://dev.mysql.com/doc/refman/5.0/es/string-functions.html

如果您在Sql Server中使用過此功能,請使用此功能,

Update Product set DateOfLastUpdate = GetDate()

然后使用My Sql

Update Product set DateOfLastUpdate = CURDATE();

您可以使用:

udpate Products set DateOfLastupdate= current_date();

要么

udpate table tblName set mytime =concat(current_date(),TIME(mytime))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM