Set current date and time to timestamp in MySQL

MySQLMySQLi Database

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)
raja
Published on 23-Aug-2019 11:13:54
Advertisements