Click here to Skip to main content
15,889,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my mysql query to filter data in DB:
SQL
$MyQuery = 'SELECT * FROM `class` WHERE `Date` >= CURDATE() AND CURTIME() < End_Time';


I should get data base on that query.

But if I input my
SQL
End Time
less then
SQL
CURTIME()
and
SQL
Date
is equal or grater then
SQL
CURDATE()
i got empty data!

What I have tried:

Change datatype in database still got error when execute data in database base on this query
$MyQuery = 'SELECT * FROM `class` WHERE `Date` >= CURDATE() AND CURTIME() < End_Time';
Posted
Updated 2-Sep-16 13:21pm

You where clause looks a little muddled:

So your clause says that:
`Date` is greater than (or equal to) now
End_Time is greater than now

Maybe that's correct? I don't know what you need your query to do, but it looks like your going for a date range between Date and End_Time?

in which case you can use between:
SQL
WHERE CURDATE() between `Date`  AND  End_Time

Between is inclusive at both ends so may not be perfect

If that's not the issue then please clarify the context of the dates and the query in general
 
Share this answer
 
v2
 
Share this answer
 
It would be easier to use NOW() and compare to a DateTime value.
Otherwise, a rewriting of WHERE clause is needed.
To something like:
JavaScript
$MyQuery = 'SELECT * FROM `class` WHERE `Date` > CURDATE() OR (`Date` = CURDATE() AND CURTIME() < End_Time )';
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900