I need to write a query in which I should compare current time with a variable which contains some time.
SQL Query:
select time >= curtime() from appointment;
Here time
is the variable which has some time.
This is the error I'm 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.
Is appointment.time
a DATETIME
or similar data type, or is it a string?
It's probably best for your system's integrity if it's a DATETIME
or TIMESTAMP
, not a string.
At any rate try this
select CAST(time AS DATETIME) >= CURTIME()
The way you've written your expression probably relies on some automatic type coercion, and it's better to make it explicit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With