How to compare current time with time variable in MySQL
I need to write a query in which I have to compare the current time with a variable that contains some time.
SQL query:
select time >= curtime() from appointment;
Here time
is a variable that has some time.
This is the error I am getting:
Illegal mix of collations (utf8_general_ci,IMPLICIT) and (latin1_swedish_ci,NUMERIC) for operation '>='; nested exception is java.sql.SQLException: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (latin1_swedish_ci,NUMERIC) for operation '>='
I've already tried using time (now ()), but it doesn't work.
source to share
Is appointment.time
a DATETIME
or a similar data type, or is it a string?
This is probably the best fit for your system integrity if it is DATETIME
or TIMESTAMP
and not a string.
Anyway, try this
select CAST(time AS DATETIME) >= CURTIME()
The way you wrote your expression probably depends on some automatic type coercion, and it is better to make it explicit.
source to share