1

I'm trying to query all data with dates that are greater or equal to >= than the current date.

Note:

  • The format of the dates in the columndate column is YYYY-MM-DD.
  • I used database,table,columndate to represent the database,table, and column for simplicity.
  • MySQL 5.5 (version)

//STATEMENT

SELECT * FROM database.table WHERE columndate >= CONVERT(VARCHAR(10),GETDATE(),120);

Question: Why is my sql statement failing?

10
  • MySQL or MS SQL Server? Don't tag products not involved. Commented Nov 30, 2015 at 8:38
  • 1
    Why are you converting current date to a varchar? Compare the dates, not some strings. Commented Nov 30, 2015 at 8:39
  • @jarlh I changed it sorry just populated so tagged it. Also I as doing VARCHAR(10) so it would only print the date not time. Commented Nov 30, 2015 at 8:42
  • First, what does your table layout look like, and second, (say it with me now) What does the error message say? Commented Nov 30, 2015 at 8:44
  • 2
    I do know how do read, @JordanDavis, but I can't read what isn't there, like the type of your date column. Second, however obscure an error message might be, odds are good someone might be able to suss it out, but only if you tell us what it says. Commented Nov 30, 2015 at 8:55

2 Answers 2

3

You can do it that way:

SELECT * FROM database.table WHERE columndate >= CURDATE();
Sign up to request clarification or add additional context in comments.

1 Comment

@JordanDavis Glad i helped.
-1
 SELECT * FROM database.table WHERE CONVERT(VARCHAR(10),columndate,120) >= CONVERT(VARCHAR(10),GETDATE(),120);

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.