这是我的表:
| date | open | close |
-----------------------------
| 2016-08-05 | 04:00 | 05:00 |
| 2016-05-05 | 05:00 | 06:00 |
| 2016-09-05 | 06:00 | 07:00 |
我需要做出这些陈述:
if ($todaydate == date && open <= $todaytime <=close) {
// go to some link
}else{
// failed alert
}
如何获得$todaydate
和$todaytime
?
答案 0 :(得分:2)
您可以在SQL中完全执行此操作:
SELECT NOW() BETWEEN CONCAT(date, ' ', open, ':00') AND CONCAT(date, ' ', close, ':00') AS `store_is_open`
FROM `my_table`
在javascript中:
var openDate = new Date(date + ' ' + open).getTime();
var closeDate = new Date(date + ' ' + close).getTime();
var now = new Date().getTime();
console.log(openDate <= now && now <= closeDate);
答案 1 :(得分:-1)
您可以将存储的日期和时间转换为时间戳,然后您可以轻松地将当前时间戳与存储的时间戳进行比较。