我无法确定预订期是否结束?
我有2 console.log(Number.MAX_VALUE + 123);
console.log(Number.MAX_VALUE + Number.MAX_VALUE);
/* Is (Number.MAX_VALUE + Number.MAX_VALUE) a number? */
console.log(Number.isInteger(Number.MAX_VALUE + Number.MAX_VALUE));
这样开始 => unix timestamp
和结束 => 2017-06-20 12:00:00
每次运行2017-06-23 12:00:00
时,我想从我当前的query
(我可以使用{传递时间)检查时间是否已经过去(即,是否达到预订期限) {1}})
我的伪代码:
date
}
期望的解决方案:我正在寻找php
特定的解决方案,也欢迎良好的 select timestampdiff(DAY, '2017-06-20 12:00:00', '2017-06-23 12:00:00'); returns 3
returnedDate = 3; // returns difference either in date format or no.of days
if((returnedDate - mycurrentDate) == 0){
//your booking period is over
}else{
// no of remaining days
解决方案。
问题:如何知道预订日期已过期?
请帮我解决这个问题,提前谢谢!!!
答案 0 :(得分:1)
假设mycurrentDate
为NOW()
,start
和end
是事件发生的日期,预订的阈值为end
日期。
您可以使用DATEDIFF
来确定事件结束前剩余的天数,并检查结束日期是否已经过去,以便事件显示为0.
EG:事件结束前几天
演示:http://sqlfiddle.com/#!9/95b548/2
假设NOW()
2017-06-21 12:00:00
使用过去,当前和未来事件。
| id | start | end |
|----|---------------------|---------------------|
| 1 | 2017-06-20T12:00:00 | 2017-06-23T12:00:00 | #current
| 2 | 2017-06-01T12:00:00 | 2017-06-03T12:00:00 | #past
| 3 | 2017-07-01T12:00:00 | 2017-07-03T12:00:00 | #future
SELECT
id,
NOW() AS `current_date`,
`tn`.`start` AS `starts_on`,
`tn`.`end` AS `ends_on`,
IF(`tn`.`end` >= NOW(),
DATEDIFF(`tn`.`end`, NOW()), #show days until event ends
0 #the event has already passed
) AS `days_remaining`
FROM `table_name` AS `tn`
结果:
| id | current_date | start | end | days_remaining |
|----|---------------------|------------------------|------------------------|----------------|
| 1 | 2017-06-21T12:00:00 | June, 20 2017 12:00:00 | June, 23 2017 12:00:00 | 2 |
| 2 | 2017-06-21T12:00:00 | June, 01 2017 12:00:00 | June, 03 2017 12:00:00 | 0 |
| 3 | 2017-06-21T12:00:00 | July, 01 2017 12:00:00 | July, 03 2017 12:00:00 | 12 |
如果end
存储为unix时间戳,您可以使用FROM_UNIXTIME()
将其转换为DATETIME值:
IF(FROM_UNIXTIME(`tn`.`end`) >= NOW(),
DATEDIFF(FROM_UNIXTIME(`tn`.`end`), NOW()),
0
) AS `days_remaining`