![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Set current date and time to timestamp in MySQL
Let us first create a table. One of the columns is set as TIMESTAMP −
mysql> create table DemoTable648( UserId int NOT NULL AUTO_INCREMENT,UserLoginTime TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARYKEY(UserId) ); Query OK, 0 rows affected (0.66 sec)
Insert some records in the table using insert command. Here, we have set the current date and time to timestamp column using the NOW() method −
mysql> insert into DemoTable648(UserLoginTime) values(NOW()); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable648;
This will produce the following output −
+--------+---------------------+ | UserId | UserLoginTime | +--------+---------------------+ | 1 | 2019-07-18 21:11:50 | +--------+---------------------+ 1 row in set (0.00 sec)
Advertisements