- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to validate expiry date on a MySQL query?
You can use NOW() for this. Following is the syntax −
select * from yourTableName where yourColumnName> now();
Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, expiryDateOfMedicine datetime ); Query OK, 0 rows affected (0.55 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-27 11:29:00'); Query OK, 1 row affected (0.36 sec) mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-26 10:39:21'); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-28 11:30:10'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(expiryDateOfMedicine) values('2019-04-29 12:44:11'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+----+----------------------+ | Id | expiryDateOfMedicine | +----+----------------------+ | 1 | 2019-04-27 11:29:00 | | 2 | 2019-04-26 10:39:21 | | 3 | 2019-04-28 11:30:10 | | 4 | 2019-04-29 12:44:11 | +----+----------------------+ 4 rows in set (0.00 sec)
Following is the query to validate expiry date on a MySQL query −
mysql> select * from DemoTable where expiryDateOfMedicine > now();
This will produce the following output −
+----+----------------------+ | Id | expiryDateOfMedicine | +----+----------------------+ | 3 | 2019-04-28 11:30:10 | | 4 | 2019-04-29 12:44:11 | +----+----------------------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL query to find expiry date (record) from the next 2 days?
- How to set cookies expiry date in JavaScript?
- How to check windows certificate expiry date using PowerShell?
- Validate Date in MySQL using a custom function
- How to validate a date pattern in JavaScript?
- MySQL query to make a date column NULL?
- MySQL query to select date >= current date - 3 weeks?
- How to filter a query on specific date format with MongoDB?
- MySQL query with two boolean conditions to extract date based on hour?
- How to represent fixed date like credit card expiry, YearMonth in java 8?
- How to get the certificate's start and expiry date using PowerShell?
- MySQL query to select records with a particular date?
- MySQL query to return the entire date and time based on a string and format
- MySQL query to select date from timestamp?
- MySQL query to insert row with date?

Advertisements