Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set current date in the datetime field

Tags:

datetime

mysql

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?

like image 510
You Kuper Avatar asked Jan 07 '13 13:01

You Kuper


People also ask

How do you set a datetime field to automatically use current date?

In the Date and time dialog box, select the format you want. Select the Update automatically check box. The date is inserted as a field and will update automatically.

How do I assign a current date to a column in SQL?

To update with the current date and time: UPDATE table_name SET date_field = CURRENT_TIMESTAMP; To update with a specific date value: UPDATE table_name SET date_field = 'YYYY-MM-DD HH:MM:SS.

How do you insert the current date in a column?

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.

How do I insert the current date automatically in SQL?

With the help of CURDATE() and NOW() function, we can insert current date automatically in a column of MySQL table.


2 Answers

You can use -

update table tblName set mytime = current_date()

Or

update table tblName set mytime =concat(current_date(),' ',TIME(mytime))
like image 76
Suresh Kamrushi Avatar answered Sep 20 '22 01:09

Suresh Kamrushi


Use below query..

update Table1 set mytime=now();
like image 45
Siddharth Reddy Avatar answered Sep 21 '22 01:09

Siddharth Reddy