MySQL Date with not null

Date with not null

In this page, we have discussed how to test if a date value is not NULL.


Sample table: newpublisher


SELECT pub_name,pub_city,country,estd 
FROM newpublisher         

Relational Algebra Expression:

Relational Algebra Expression: Date with not null.

Relational Algebra Tree:

Relational Algebra Tree: Date with not null.


The above MySQL statement will filter the rows whose estd date is NOT NULL.

Sample Output:

mysql> SELECT pub_name,pub_city,country,estd 
    -> FROM newpublisher         
    -> WHERE estd IS NOT NULL;
| pub_name                 | pub_city  | country | estd       |
| Jex Max Publication      | New York  | USA     | 1969-12-25 | 
| BPP Publication          | Mumbai    | India   | 1985-10-01 | 
| Ultra Press Inc.         | London    | UK      | 1948-07-10 | 
| Summer Night Publication | New York  | USA     | 1990-12-10 | 
| Novel Publisher Ltd.     | New Delhi | India   | 2000-01-01 | 
5 rows in set (0.00 sec)

PHP script:

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>example-date-with-not-null php mysql examples | w3resource</title>
<meta name="description" content="example-date-with-not-null php mysql examples | w3resource">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<div class="container">
<div class="row">
<div class="col-md-12">
<h2>List of publishers with their city, country and date of establishment, if date of establishment is available:</h2>
<table class='table table-bordered'>
<th>Publisher's name</th><th>Date of establishment</th><th>Current date</th><th>AGE</th>
$db = "your_dbname";
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
foreach($dbh->query('SELECT pub_name,pub_city,country,estd FROM newpublisher WHERE estd IS NOT NULL') as $row) {
echo "<tr>";
echo "<td>" . $row['pub_name'] . "</td>";
echo "<td>" . $row['pub_city'] . "</td>";
echo "<td>" . $row['country'] . "</td>";
echo "<td>" . $row['estd'] . "</td>";
echo "</tr>";

View the example in browser

Previous: Date Calculation using order by
Next: Date with where

Share this Tutorial / Exercise on : Facebook and Twitter