1

we have a store procedure, the IN parameter is DATE today. in this procedure, a aql is to compare this today value with a table which has a timestamp column. for example:

column A
2012-12-01 00:00:00

SQL:

select * from t where A = today.

We run this procedure in phpmyadmin, it run OK. but it's not work in command line.

Why?

1
  • What exactly does the query look like and what exactly doesn't work how? Commented Jan 6, 2013 at 13:33

2 Answers 2

4

Guess you may need to format both dates into a common format.. To be safe you may even add Date() or str_to_Date if required...if you are not sure column A contains a proper date...

Try this please:

SELECT * FROM tablename
WHERE DATE_FORMAT(A, '%d/%m/%Y') = DATE_FORMAT(TODAY, '%d/%m/%Y');

if you meant CURDATE() by today then try this as well,

SELECT * FROM tablename
WHERE DATE_FORMAT(A, '%d/%m/%Y') = DATE_FORMAT(CURDATE(), '%d/%m/%Y');
Sign up to request clarification or add additional context in comments.

1 Comment

I would upvote this a thousand times if I could. you just saved me from a nightmare that haunted me yesterday. seriously
1

It's possible that the dates are in different formats and that's causing them to be not equal. You can use datediff(date1, date2) = 0 to fix this.

http://www.w3schools.com/sql/func_datediff_mysql.asp

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.