Reputation: 2495
I have a table in which I have two fields i.e name of the product and release date (type:date)...
->>I want to select all the products which have not been launched yet!!!
Thanks...
Upvotes: 1
Views: 229
Reputation: 95
also need to include null values
SELECT * FROM products
WHERE DATEDIFF(release_date
, CURDATE()) > 1 or 'release_date' is null
Upvotes: 0
Reputation: 19325
Another alternative
SELECT * FROM `products` WHERE DATEDIFF(`release_date`, CURDATE()) > 1
Upvotes: 0
Reputation: 18381
select product_name
from products
where release_date > CURRENT_TIMESTAMP
Upvotes: 2
Reputation: 95203
You can use CURRENT_TIMESTAMP
to get the current date and time. MySQL will natively compare two dates, so that's a plus. Therefore, all you have to do is grab all of the products with a release_date
greater than the CURRENT_TIMESTAMP
.
select
product_name
from
products
where
release_date > CURRENT_TIMESTAMP
Note that this can be historical, too. So, you could substitute any date for CURRENT_TIMESTAMP
and get all of the products that hadn't (or had, if you did less than (<)) been released by that date, like so:
where
release_date > '7/1/2009'
Read up on the MySQL Date and Time functions for more info on how you can manipulate dates to do some really neat queries.
Upvotes: 2
Reputation: 94237
How about something like:
SELECT * FROM products WHERE release_date > NOW()
Upvotes: 0