How to check if a timestamp is set in MySQL?

MySQLMySQLi Database

Let us first create a table −

mysql> create table DemoTable855(DueDate timestamp);
Query OK, 0 rows affected (0.54 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable855 values('2019-08-07');
Query OK, 1 row affected (0.15 sec)
mysql> insert into DemoTable855 values('0000-00-00');
Query OK, 1 row affected (0.27 sec)
mysql> insert into DemoTable855 values('2019-07-06');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable855 values('2016-04-10');
Query OK, 1 row affected (0.16 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable855;

This will produce the following output −

+----------------------+
| DueDate             |
+----------------------+
| 2019-08-07 00 −00 −00|
| 0000-00-00 00 −00 −00|
| 2019-07-06 00 −00 −00|
| 2016-04-10 00 −00 −00|
+----------------------+
4 rows in set (0.00 sec)

Following is the query to check if a timestamp is set in MySQL −

mysql> select *from DemoTable855 where DueDate > 0;

This will produce the following output −

+----------------------+
| DueDate              |
+----------------------+
| 2019-08-07 00 −00 −00|
| 2019-07-06 00 −00 −00|
| 2016-04-10 00 −00 −00|
+----------------------+
3 rows in set (0.03 sec)
raja
Published on 03-Sep-2019 12:22:57
Advertisements