0
Select * from table where Startdatetime<='".$currentdatetime."' AND '".$currentdatetime."'<=t.Enddatetime

$currentdatetime is my variable containing the current date and time in 'Y-m-d H:i:s' format.

My problem is that MySQL is checking the date part properly, but the time is not considered in the check. What am I doing wrong?

RichardBernards
  • 3,146
  • 1
  • 22
  • 30

1 Answers1

0

Force the variable date time values to match the mysql datetime format and the use it in query

date('Y-m-d H:i:s', strtotime($currentdatetime))

Also make sure database field is of data type datetime.

Aditya
  • 1,241
  • 5
  • 19
  • 29
  • "$currentdatetime is my variable containing the current date and time in **'Y-m-d H:i:s'** format." – Ja͢ck Dec 05 '14 at 11:15