Say,i've to select a value from today to next sunday. How to input date?
Is there any keyword like FROM = 26-12-2001 TO = 30-12-2001
Say,i've to select a value from today to next sunday. How to input date?
Is there any keyword like FROM = 26-12-2001 TO = 30-12-2001
You would typically use BETWEEN for this
WHERE YourDate BETWEEN '26-12-2001' AND '30-12-2001'
although other common comparison operators can be used as well
WHERE YourDate >= '26-12-2001' AND Yourdate < '31-12-2001'
Note the use of 31/12/2001 when using the lesser then comparison operator
Use between
. In your case it would between date1 and date2
SELECT * FROM your_table_name
WHERE your_tables_date_column
BETWEEN date1 and date2
Account for time if recorded with:
SELECT * FROM your_table_name
WHERE DATE_FORMAT(your_tables_date_column, '%Y-%m-%d 00:00:00')
/* Oracle trunc(col) equivalent */
between date1 and date2
It works for strings too, e.g.
SELECT * FROM Persons
WHERE lower(last_name)
BETWEEN 'smith' AND 'webster'
and for numbers e.g.
SELECT * FROM Persons
WHERE height
BETWEEN 1 and 3 /* meters, i.e. exclude kids */
and you can also use the negative, e.g.
SELECT * FROM Persons
WHERE lower(last_name)
NOT BETWEEN 'smith' AND 'webster'
btw the literal answer to your questions is something like:
SELECT * from tbl where date_field BETWEEN
CURDATE() AND
DATE_ADD(CURDATE(), INTERVAL (8 - IF(DAYOFWEEK(CURDATE())=1, 8, DAYOFWEEK(CURDATE()))) DAY) AS NEXTSUNDAY
/* Watch for performance issues with indexes when using functions on columns */