PHP日期时间介于两个2之间

时间:2014-08-25 19:09:55

标签: php datetime

我正在制作一个计划应用程序,并且我坚持使用以下逻辑。 我有一系列时间段,如果当前时间是晚上7点以后,我想隐藏第二天上午9:00之前的时段。例如,如果当前时间日期是8/25/2014 7:01 pm,则不应出现在2014年8月26日上午9:00之前的所有时间段。

我试过这个

if(date('Y-m-d H:i:s', strtotime('7:00pm')) <= $from && $from <= date('Y-m-d H:i:s', strtotime('+1 day 9:00am')) && $now > date('Y-m-d H:i:s', strtotime('7:00pm')))
                continue; 

但是strtotime('7:00pm')当天晚上7点返回。

问题是如何获取日期时间,即$from下午7点的前一天?

1 个答案:

答案 0 :(得分:0)

尝试将日期$从晚上7点连接起来,例如:

$start_date = $date('Y-m-d', $from)." "."7:00pm";
// then use it in strtotime
date('Y-m-d H:i:s', strtotime($start_date));