How to insert timestamp value in MySQL example

Let’s see how to insert timestamp in MySQL example. Here we will see MySQL timestamp example code.

To insert timestamp value we have to insert timestamp in the format of

YYYY-MM-DD hh:mm:ss

  • YYYY is year
  • MM is month
  • DD is day
  • hh is hour
  • mm is minute
  • ss is seconds

MySQL Timestamp Example

We have attendance table where login and logout has timestamp column.

mysql> describe attendance;
+--------+-----------+------+-----+---------+-------+
| Field  | Type      | Null | Key | Default | Extra |
+--------+-----------+------+-----+---------+-------+
| empid  | int       | YES  |     | NULL    |       |
| login  | timestamp | YES  |     | NULL    |       |
| logout | timestamp | YES  |     | NULL    |       |
+--------+-----------+------+-----+---------+-------+
3 rows in set (0.04 sec)

We will insert timestamp value in login and logout column.

insert into attendance values(101,'2023-12-01 09:05:03','2023-12-01 17:00:03');

Now table will look like

select * from attendance;
+-------+---------------------+---------------------+
| empid | login               | logout              |
+-------+---------------------+---------------------+
|   101 | 2023-12-01 09:05:03 | 2023-12-01 17:00:03 |
+-------+---------------------+---------------------+
1 row in set (0.00 sec)
Scroll to Top