【问题标题】:PHP datetime between two 2 values两个 2 值之间的 PHP 日期时间
【发布时间】:2014-08-25 19:09:54
【问题描述】:

我正在制作一个调度应用程序,但我坚持以下逻辑。 我有一组时间段,如果当前时间在晚上 7:00 之后,我想隐藏第二天上午 9:00 之前的时间段。例如,如果当前时间日期是 8/25/2014 7:01pm ,则不应显示 8/26/2014 上午 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:00 返回当天。

问题是如何获取日期时间,即$fromat 7:00pm 的前一天?

【问题讨论】:

  • $from 到底是什么?就一天?准确的时间?
  • 一个php日期对象,$from = date("Y-m-d H:i:s", $start_time);
  • PHP 没有日期对象。 date() 是一个返回字符串的函数。

标签: php datetime


【解决方案1】:

尝试将日期 $from 与晚上 7:00 连接起来,例如:

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

【讨论】:

  • 我要前一天$from
  • 例如,如果$from 是 8/25/2014,我需要日期时间是 8/24/2014 7:00pm
  • @MahAbdelaziz 没问题,希望对您有所帮助!
猜你喜欢
  • 1970-01-01
  • 2023-03-11
  • 2010-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多