0

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: 2011-06-10 second shows ; 2011-06-02

it shows all rows of table

4
  • What happens if you directly input the date that you are comparing the STR_TO_DATE output to, e.g., STR_TO_DATE(...) >= '2011-06-02' Commented Jun 2, 2011 at 7:57
  • 3
    Have you tried: Select * from tblconcertdetail WHERE STR_TO_DATE(Concert_Date,'%m/%d/%Y')>= curdate() ? Commented Jun 2, 2011 at 7:59
  • Concert_Date is a date/datetime/timestamp? Commented Jun 2, 2011 at 8:07
  • PS: 2011-06-10 is greater than/equal to 2011-06-02. This row should be displayed. Commented Jun 2, 2011 at 8:08

2 Answers 2

1

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".

Sign up to request clarification or add additional context in comments.

2 Comments

no i have taken Concert_Date as string type for easyness at time of inserting data
@user755230: if it were possible to downvote a comment I would have done so!
0

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.

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.