In MySQL, now() can be used to insert the current date/time. The syntax is as follows -
insert into yourTableName values(now());
To understand the above concept of inserting current date/time in a table, let us first create a table -
mysql> create table CurrentDateTimeDemo −> ( −> YourTime datetime −> ); Query OK, 0 rows affected (0.58 sec)
Use now() to insert the current date/time. The query is as follows -
mysql> insert into CurrentDateTimeDemo values(now()); Query OK, 1 row affected (0.20 sec)
Now you can check if the current date/time is inserted or not-
mysql> select *from CurrentDateTimeDemo;
The following output shows the successful insertion of the current date using now():
+---------------------+ | YourTime | +---------------------+ | 2018-12-08 19:08:41 | +---------------------+ 1 row in set (0.00 sec)
The above is the detailed content of How to insert current date/time in a field using now() using MySQL?. For more information, please follow other related articles on the PHP Chinese website!