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.
Example:
Sample table: newpublisher
Code:
SELECT pub_name,pub_city,country,estd
FROM newpublisher
WHERE estd IS NOT NULL;
Relational Algebra Expression:
Relational Algebra Tree:
Explanation
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">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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">
</head>
<body>
<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'>
<tr>
<th>Publisher's name</th><th>Date of establishment</th><th>Current date</th><th>AGE</th>
</tr>
<?php
$hostname="your_hostname";
$username="your_username";
$password="your_password";
$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>";
}
?>
</tbody></table>
</div>
</div>
</div>
</body>
</html>
Previous: Date Calculation using order by
Next: Date with where
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/mysql/advance-query-in-mysql/date-with-not-null.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics