problem comparing two dates in mysql
I m using below query from c# to compare current date with date stored in database as string.but it do not show the proper output even though it is not showing any error.
Select * from tblconcertdetail
WHERE STR_TO_DATE(Concert_Date,'%m/%d/%Y')>="+DateTime.Now.ToString("yyyy-MM-dd")+";
first argument shows as: 201开发者_JS百科1-06-10 second shows ; 2011-06-02
it shows all rows of table
Are you sure the first argument returns as you said YYYY-MM-DD???? Make sure the value for "Concert_Date" should look like "04/22/2011".
Try the following:
Select * from tblconcertdetail where date(Concert_Date) >= "+DateTime.Now.ToString("yyyy-MM-dd")+";
I think Concert_Date is of datatype "date" or "datetime" or "timestamp".
The output of STR_TO_DATE(Concert_Date,'%m/%d/%Y')
depends on Concert_Date
.
Its different values will produce different results if compared to the second date.
I think you should try to use this portion of code:
STR_TO_DATE('2011-06-10','%Y-%m-%d');
IMHO if Concert_Date
is equal to 2011-06-10
you cannot read it correctly with '%m/%d/%Y'
patern.
精彩评论