Home > Database > Mysql Tutorial > body text

How to insert current date/time in a field using now() using MySQL?

PHPz
Release: 2023-09-18 21:05:02
forward
1101 people have browsed it

如何使用 MySQL 在字段中使用 now() 插入当前日期/时间?

In MySQL, now() can be used to insert the current date/time. The syntax is as follows -

insert into yourTableName values(now());
Copy after login

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)
Copy after login

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)
Copy after login

Now you can check if the current date/time is inserted or not-

mysql> select *from CurrentDateTimeDemo;
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!