且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何确定日期是否在PHP之间的两个日期之间?

更新时间:2023-01-27 17:27:05

从PHP 5.3开始:

As of PHP 5.3:

$paymentDate = DateTime::createFromFormat('d/m/Y', '31/12/2010');
$contractDateBegin = DateTime::createFromFormat('d/m/Y', '01/01/2001');
$contractDateEnd = DateTime::createFromFormat('d/m/Y', '01/01/2012');

if ($paymentDate >= $contractDateBegin && $paymentDate <= $contractDateEnd)
{
  echo "is between\n";
}

您可能需要调整使用 = ,具体取决于日期是否排他。

You may need to adjust the use of <= to < depending on whether or not the dates are exclusive.