tags:

views:

119

answers:

6

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...

A: 

How about something like:

SELECT * FROM products WHERE release_date > NOW()

zombat
+2  A: 

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.

Eric
A: 

It's depends upon how you set value of release date.

SELECT * FROM products WHERE release_date is null
adatapost
+2  A: 
select product_name
from products
where release_date > CURRENT_TIMESTAMP
Ben Griswold
Thanks a lot!!!
halocursed
A: 

Another alternative

SELECT * FROM `products` WHERE DATEDIFF(`release_date`, CURDATE()) > 1
Extrakun
A: 

also need to include null values

SELECT * FROM products WHERE DATEDIFF(release_date, CURDATE()) > 1 or 'release_date' is null

Yogi