- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to insert current date/ time using now() in a field with MySQL?
In MySQL, now() can be used to insert current date/time. The syntax is as follows −
insert into yourTableName values(now());
To understand the above concept of inserting current date/time in the table, let us first create a table −
mysql> create table CurrentDateTimeDemo −> ( −> YourTime datetime −> ); Query OK, 0 rows affected (0.58 sec)
Inserting current date/time using now(). The query is as follows −
mysql> insert into CurrentDateTimeDemo values(now()); Query OK, 1 row affected (0.20 sec)
Now you can check the current date/time has been inserted or not −
mysql> select *from CurrentDateTimeDemo;
The following output displays that the current date is successfully inserted using now():
+---------------------+ | YourTime | +---------------------+ | 2018-12-08 19:08:41 | +---------------------+ 1 row in set (0.00 sec)
Advertisements