8

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 Kuper
  • 1,113
  • 7
  • 18
  • 38

7 Answers7

13

You can use -

update table tblName set mytime = current_date()

Or

update table tblName set mytime =concat(current_date(),' ',TIME(mytime))
Suresh Kamrushi
  • 15,627
  • 13
  • 75
  • 90
5

Use below query..

update Table1 set mytime=now();
2
UPDATE Table1
SET mytime = CONCAT_WS(' ',CURDATE(), TIME(myTime))
John Woo
  • 258,903
  • 69
  • 498
  • 492
2
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.

barbsan
  • 3,418
  • 11
  • 21
  • 28
user1955162
  • 797
  • 2
  • 6
  • 21
0

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) ) 
Fathah Rehman P
  • 8,401
  • 4
  • 40
  • 42
0
UPDATE test
SET mytime = mytime + INTERVAL DATEDIFF(CURRENT_DATE(),DATE(mytime)) DAY  ;
ypercubeᵀᴹ
  • 113,259
  • 19
  • 174
  • 235
0

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.

kanine
  • 45
  • 1
  • 6