select date_format(Fromdate,'%m/%d/%Y') as 'Fromdate' ,date_format(Todate,'%m/%d/%Y') as 'Todate'
FROM tbl_sitemaster
where Fromdate >= '2012-05-01'
and Todate <= '2012-05-07';
I have a table consisting of Fromdate column and Todate column. Select query should retrive data between a certian range of date. Query works for Fromdate only but when i specify both Fromdate and Todate condition, its not retriveing any data even though
there is data in table in that range. am using mysql
Datta H Shed...
Member
228 Points
104 Posts
Problem with select Query to specify date range in Mysql.
May 07, 2012 06:29 AM|LINK
select date_format(Fromdate,'%m/%d/%Y') as 'Fromdate' ,date_format(Todate,'%m/%d/%Y') as 'Todate'
FROM tbl_sitemaster
where Fromdate >= '2012-05-01'
and Todate <= '2012-05-07';
I have a table consisting of Fromdate column and Todate column. Select query should retrive data between a certian range of date. Query works for Fromdate only but when i specify both Fromdate and Todate condition, its not retriveing any data even though there is data in table in that range. am using mysql
tusharrs
Contributor
3230 Points
668 Posts
Re: Problem with select Query to specify date range in Mysql.
May 07, 2012 06:35 AM|LINK
refer to this link http://archive.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=FindDataBetweenDates
still problem exists then
post some sample data
( Mark as Answer if it helps you out )
View my Blog
Datta H Shed...
Member
228 Points
104 Posts
Re: Problem with select Query to specify date range in Mysql.
May 07, 2012 06:48 AM|LINK
Between clause suggested by u works for one column to compare But I have two date columns in my table i.e FromDate column and Todate column.
tusharrs
Contributor
3230 Points
668 Posts
Re: Problem with select Query to specify date range in Mysql.
May 07, 2012 06:58 AM|LINK
give some sample data for your dates
( Mark as Answer if it helps you out )
View my Blog
tusharrs
Contributor
3230 Points
668 Posts
Re: Problem with select Query to specify date range in Mysql.
May 07, 2012 10:11 AM|LINK
here 103 format means dd/MM/yyyy
so use it for date columms and compare the date as string in the same format
fromdate is checked for >= to 1st jan 2011 and todate is checked for less than equal to 20th Dec 2012
( Mark as Answer if it helps you out )
View my Blog