There is a datetime field in the MySQL table:
`mytime` datetime
It contains entries like '2012-02-10 10:15'.
How to set the date part to the current date?
There is a datetime field in the MySQL table:
`mytime` datetime
It contains entries like '2012-02-10 10:15'.
How to set the date part to the current date?
You can use -
update table tblName set mytime = current_date()
Or
update table tblName set mytime =concat(current_date(),' ',TIME(mytime))
UPDATE table SET mytime = CONCAT(CURDATE(), ' ' , time(mytime)) WHERE id = row;
I think this will work, my syntax may be off. time(mytime)
may give you hour:minute:seconds
while you are only looking for hour:minute
. I think you also need the ' '
in there so MySQL will recognize the time format.
suppose your table is as follows
CREATE TABLE `table66` (
`id` INT(10) NULL DEFAULT NULL,
`mytime` DATETIME NULL DEFAULT NULL
)
Then you can use following query to update your mytime column
update table66 set mytime=concat(date(now()),' ',time(mytime) )
UPDATE test
SET mytime = mytime + INTERVAL DATEDIFF(CURRENT_DATE(),DATE(mytime)) DAY ;
The question is quite vague but comes up top on a Google Search.
In general just use now()
to set a datetime column with the current date AND time. Whether an insert, update or trigger it doesn't matter.
Several answers here have updates without a where clause. Most updates would have a where clause so as not to affect the whole table.