簡體   English   中英

如果日期在這兩個日期之間,則

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

我有一個$bonus["from_date"]$bonus["to_date"] ,它們的格式是:yyyy-mm-dd我想檢查今天的日期是否在這兩個日期之間。

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

我怎樣才能做到這一點?

看看strtotime()

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

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

您可以使用標准比較運算符:

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

之所以起作用,是因為您首先將其存儲為具有最大日期元素的字符串。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM