Mysql between query not working
NickName:Aditya Ekbote Ask DateTime:2014-04-11T17:36:22

Mysql between query not working

I am using mysql. I want to display records between two dates. I searched through web and found that mysql's date format is yyyy/mm/dd. so I am writing query as follows,

select 
    * 
from tbl_reservation 
where 
    current_date between '2014-03-28' and '2014-03-26';

But, I don't know why it is not working. "col_date" has DATE datatype. I am not storing time in it.

Let me give you some idea what i have done at back end,

SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Date curr_date=new Date();
String compareDate=sdf.format(curr_date);

And I am storing this value in "col_date". Is it happening because of this processing?

Thanks for your valuable time in advance.

Copyright Notice:Content Author:「Aditya Ekbote」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/23008860/mysql-between-query-not-working

Answers
Ravinder Reddy 2014-04-11T09:38:05

With BETWEEN, use least date first, latest date next \n\nIt should be: \n\nselect * from tbl_reservation \nwhere col_date between '2014-03-26' -- least date\n and '2014-03-28'; -- latest date\n",


zkanoca 2014-04-11T09:39:41

Write lower date value first.\n\nSELECT * FROM tbl_reservation WHERE col_date BETWEEN '2014-03-26' AND '2014-03-28'\n",


More about “Mysql between query not working” related questions

Mysql between query not working

I am using mysql. I want to display records between two dates. I searched through web and found that mysql's date format is yyyy/mm/dd. so I am writing query as follows, select * from

Show Detail

PHP Mysql Select query with BETWEEN

I am trying to use two query using between but when I add the between code it does not work. This is the code that is working for me before using BETWEEN. $result = mysql_query("SELECT name , lik...

Show Detail

MySQL Between Query

I need a small help in mysql. Following is my table structure I just wanted to know how can I get a result from 5/30/2011 to 6/30/2011 with a proper sql query. I tried with Between query but its not

Show Detail

Mysql: Query not working properly, not selecting 12:00 in where between

mysql between not working as expected. Query I have now: Table::where(function ($query) use ($time_in, $time_out) { $query->orWhereRaw("? between time_in AND time_out", [$time_in.":...

Show Detail

mysql query in between dates not working

I have the following mysql table: tasks: ===================== tid status desc duedate And i have the following records in that table: records =========================== 1 active Test descrip

Show Detail

MySQL Between Query not working for two time

I have written this MySQL query to filter data, I think in query works, if it get equal values but it doesn't work for between values. Please help me to sort out this issue.. SELECT * FROM ...

Show Detail

currentdate between not working in php query

I have mysql table with columns section, is_date_based (Yes/No values), date_start, date_end and showhide query is $query = "select * from tabele where section='Festival Wish' and ((is_date_base...

Show Detail

Why isnt my MySQL BETWEEN operator not working?

MySQL table "flightSched" is connected to time, similar to the one below: flightNo |day |time |arrivalTimeSec ============================================= WERE112 |Tuesday | 1:00 |

Show Detail

Mysql Query to get event between two dates

I am trying to get the pots between two dates. I am trying following query to fetch the data from mysql but it is now working. $start = $_POST['evnt_date_from']; $end = $_POST['evnt_date_to']; $

Show Detail

MySQL BETWEEN Query on DATETIME formate

I am reading data from MySQL database. I successfully read data where time is equal to given time by the following query (This returns me valid data from alldata table.) SELECT * FROM alldata WHER...

Show Detail