简体   繁体   English

如果日期在这两个日期之间,则

[英]If the date is between these two dates then

I have a $bonus["from_date"] and a $bonus["to_date"] , they are in this format: yyyy-mm-dd I would like to check that the todays date is between those two dates. 我有一个$bonus["from_date"]$bonus["to_date"] ,它们的格式是:yyyy-mm-dd我想检查今天的日期是否在这两个日期之间。

$today = date('Y-m-d', time());

How can i do this? 我怎样才能做到这一点?

Have a look at strtotime() 看看strtotime()

$from = strtotime($bonus['from_date']);
$to = strtotime($bonus['to_date']);
$now = time();

if($from <= $now && $to >= $now) {
    // It's between
}

You can use standard comparison operators: 您可以使用标准比较运算符:

if ($today >= $bonus['from_date'] && $today <= $bonus['to_date'])

It works because you are storing as a string with biggest date elements first. 之所以起作用,是因为您首先将其存储为具有最大日期元素的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM