2

I need to put (IF) condition in my code to show only the datediff bigger than 0 but always happen error , anybody can help me please ?

SELECT DATEDIFF(`Date` ,CURDATE()) AS Date,`id` AS Dateid
FROM `election`
ORDER BY `Date` ASC

enter image description here

i need only Date bigger than 0

9
  • 1
    Show us sample data and the error message you received. Commented Nov 17, 2016 at 13:27
  • 1
    There's no IF in the SQL language. Use WHERE/AND/OR/CASE. Commented Nov 17, 2016 at 13:28
  • @jarlh dev.mysql.com/doc/refman/5.7/en/control-flow-functions.html ? Though the rest of the comment seems right on. Commented Nov 17, 2016 at 13:29
  • @jarlh how ? can u fix it for me i need to show datediff bigger than 0 Commented Nov 17, 2016 at 13:30
  • @jarlh you sure about that? dev.mysql.com/doc/refman/5.7/en/if.html Commented Nov 17, 2016 at 13:30

1 Answer 1

1

Not very pretty, but you can just recreate the date field in the where clause to compare it:

SELECT DATEDIFF(`Date` ,CURDATE()) AS Date,`id` AS Dateid
FROM `election`
WHERE DATEDIFF(`Date` ,CURDATE()) > 0
ORDER BY `Date` ASC
Sign up to request clarification or add additional context in comments.

1 Comment

I wouldn't worry about how pretty it looks if it does the job!

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.