登录
首页 >  数据库 >  MySQL

如何在 MySQL 中插入当前日期/时间?

来源:tutorialspoint

时间:2023-08-29 09:44:42 225浏览 收藏

目前golang学习网上已经有很多关于数据库的文章了,自己在初次阅读这些文章中,也见识到了很多学习思路;那么本文《如何在 MySQL 中插入当前日期/时间?》,也希望能帮助到大家,如果阅读完后真的对你学习数据库有帮助,欢迎动动手指,评论留言并分享~

To insert current date/ time in MySQL, use the now() function. Let us now see an example.

At first, we will create a table. The CREATE command is used to create a table.

mysql > create table CurrentDateTime
-> (
-> CurrentTime datetime
-> );
Query OK, 0 rows affected (1.14 sec)

Syntax to insert the current date/time with the help of insert command and now()

mysql> insert into CurrentDateTime values(now());
Query OK, 1 row affected (0.11 sec)

To check that the current date/ time is inserted in the table or not, use the select command.

mysql> select *from CurrentDateTime;

以下是显示我们成功插入当前日期/时间的输出。

+---------------------+
| CurrentTime         |
+---------------------+
| 2018-10-18 13:14:30 |
+---------------------+
1 row in set (0.00 sec)

好了,本文到此结束,带大家了解了《如何在 MySQL 中插入当前日期/时间?》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多数据库知识!

声明:本文转载于:tutorialspoint 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>