L
L
lemonlimelike2018-02-14 02:57:35
MySQL
lemonlimelike, 2018-02-14 02:57:35

How to compare dates correctly?

Why is this request

SELECT * FROM matches WHERE CURDATE() > '2018-02-15'

compares dates incorrectly?
The table has such fields, with such dates (field type string) 5a837adf1e54b504412549.png
And you need to make two queries, such as if the current date is > (greater than) the given date in the data_event field .... and the second query if the current date is < (less than) than the date in the data_event field.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel K, 2018-02-14
@lemonlimelike

In my opinion, because in this form, mysql casts types to a string and compares them as strings.
Those. need something like this:CURDATE() > DATE('2018-02-14')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question