4

I have a list of row's in mysql tables

+--------+-----+------------+------------+------------+-----------+
| off_id | uid | leave_from | leave_to   | leave_code | reason    |
+--------+-----+------------+------------+------------+-----------+
|      1 |   1 | 2012-01-01 | 2012-01-05 | OFF        | asdsda    |
|      2 |   1 | 2012-01-15 | 2012-01-16 | OFF        | asdd      |
|      5 |   1 | 2012-02-03 | 2012-02-05 | OFF        | gfjghjhgj |
+--------+-----+------------+------------+------------+-----------+

I have to select the rows that are in between the date 2012-01-01 to 2012-01-05. How can i do this please help.

5 Answers 5

3
SELECT * 
FROM tbl
WHERE leave_from >= '2012-01-01'
AND leave_to <= '2012-01-05'
Sign up to request clarification or add additional context in comments.

Comments

2
select * from table where leave_from between '2012-01-01' and '2012-01-05'

Comments

1
SELECT Off_Id,uid,Leave_from,leave_to,leave_code
FROM YourTableName
WHERE Leave_From>="2012-01-01" and Leave_to <="2012-01-05"

Comments

1

If I understand your question right:

SELECT * FROM `table_name` 
WHERE leave_from >= "2012-01-01" AND leave_to <= "2012-01-05"

Comments

0

point 1 : you could use > < <= >= with date datatypes .

the above can be achieved by

SELECT * FROM table WHERE leave_from > '2012-01-01' AND leave_from <'2012-01-05';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.