2

I have a database which i created via PHPmyadmin. And I have problem with the time columns/calculation.

table name = course

..course_name | section_ID | Dr_ID | time_start | time_end | location 
...................................| 10:00:00 | 10:20:00 < //i but the
                                                        value like this 

And the type of (| time_start | time_end |) = Time < //like this in PHPmyadmin

And my query doesn't work. I guess the problem is .time(). in the query:

$query2 = "SELECT location FROM sections where Dr_ID = 1
           AND time_start <= ".time()." and time_end > ".time();   
2
  • could you please paste the create query for tabale here? Jun 21, 2011 at 4:39
  • 4
    Are you looking for time_start <= now() and time_end > now() perhaps? Jun 21, 2011 at 4:42

2 Answers 2

3

The time() function returns a unix timestamp, you *time_start* field seems to be a mysql TIME type you need to convert one of them to be able to make a proper comparison.

You can use date("H:i:s",time()) instead of time(), which might get you what you want

Or you need to convert your *time_start* *time_end* fields to unix timestamp UNIX_TIMESTAMP() - you will need to concatenate the date in front of your *time_start*.

0

try to use,If I understand correctly,

SELECT location FROM sections 
where Dr_ID = 1 AND (now() between time_start and time_end )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.