gpt4 book ai didi

php - 我怎样才能在mysql查询中获取当前时间?

转载 作者:行者123 更新时间:2023-11-29 02:05:43 26 4
gpt4 key购买 nike

我有一个通过 PHPmyadmin 创建的数据库。我对时间列/计算有疑问。

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

以及 (| time_start | time_end |) = Time 的类型

我的查询不起作用。我想问题是.time()。在查询中:

$query2 = "SELECT location FROM sections where Dr_ID = 1
AND time_start <= ".time()." and time_end > ".time();

最佳答案

time() 函数返回一个 unix 时间戳,你的 *time_start* 字段似乎是一个 mysql TIME 类型,你需要转换其中一个才能进行正确的比较。

您可以使用 date("H:i:s",time()) 而不是 time(),这可能会得到您想要的结果

或者您需要将 *time_start* *time_end* 字段转换为 unix 时间戳 UNIX_TIMESTAMP() - 您需要将日期连接在 *time_start* 之前。

关于php - 我怎样才能在mysql查询中获取当前时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6420375/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com