0

示例:我必须检查这些日期:-> from= 15 March 2013 &15 April 2013 在以下日期之间,无论是否有任何日子在这两个日期之间。

以下来自 db 表的数据

#       from date            to-date
-----------------------------------------
1     01 April 2013         30 April 2013   //here we will find as falling
2     01 May 2013           15 May 2013   
3     01 June 2013          20 June 2013

我只知道以下技术可用于单次日期检查,但我不知道如何比较 2 天。

// set some example data
$referenceDate = '01 April 2013';
$fromDate = '01 January 2013';
$toDate = '01 June 2013';

// convert dates to timestamps (strings to integers)
$referenceTimestamp = strtotime( $referenceDate );
$fromTimestamp = strtotime( $fromDate );
$toTimestamp = strtotime( $toDate );

// isBetween is Boolean TRUE if reference date is greater or equal fromDate and smaller or       
  equal toDate
$isBetween = $referenceTimestamp >= $fromTimestamp and $referenceTimestamp <= $toTimestamp;
4

1 回答 1

0

如果您使用的是 mysql 数据库,则可以使用BETWEEN 。

SELECT * FROM `dt_tb` WHERE year( date_column ) between 2004 and 2005

“date_column”是一个日期字段,“year”表示它只查看年份。对于完整的日期检查,试试这个:

SELECT * from `dt_tb` WHERE date_column BETWEEN "2001-01-05" AND"2001-01-10";
于 2013-04-04T08:33:58.810 回答