开发者

how can i take the current time in mysql query?

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();   


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*.


try to use,If I understand correctly,

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜