如何通过检查日期是否介于2个范围之间来使用php搜索CSV文件

如何通过检查日期是否介于2个范围之间来使用php搜索CSV文件,php,csv,Php,Csv,我以前发过一篇太模糊的帖子。我做了很多研究,认为我可以更具体一些 while(!feof($file_handle)) { $loansinfo=fgetcsv($file\u handle); //确保我们只检查我们发布的游戏的数据 如果($loansinfo[0]=$ID){ $referenceDate=$WantedDate; $fromDate=“$loansinfo[5]”; $toDate=“$loansinfo[6]”; //将日期转换为时间戳(字符串转换为整数) $refere

我以前发过一篇太模糊的帖子。我做了很多研究,认为我可以更具体一些

while(!feof($file_handle))
{
$loansinfo=fgetcsv($file\u handle);
//确保我们只检查我们发布的游戏的数据
如果($loansinfo[0]=$ID){
$referenceDate=$WantedDate;
$fromDate=“$loansinfo[5]”;
$toDate=“$loansinfo[6]”;
//将日期转换为时间戳(字符串转换为整数)
$referenceTimestamp=strotTime($referenceDate);
$fromTimestamp=STROTTIME($fromDate);
$toTimestamp=STROTTIME($toDate);

$isBetween=$referenceTimestamp>=$fromTimestamp和$referenceTimestamp从代码的外观来看,您没有检查
$isBetween
的结果

这里有一个修改过的版本,假设你的日期格式正确,它会让你更接近

while(!feof($file_handle))
{
$loansinfo=fgetcsv($file\u handle);
//确保我们只检查我们发布的游戏的数据
如果($loansinfo[0]=$ID){
$referenceDate=$WantedDate;
$fromDate=“$loansinfo[5]”;
$toDate=“$loansinfo[6]”;
//将日期转换为时间戳(字符串转换为整数)
$referenceTimestamp=strotTime($referenceDate);
$fromTimestamp=STROTTIME($fromDate);
$toTimestamp=STROTTIME($toDate);

$isBetween=$referenceTimestamp>=$fromTimestamp和$referenceTimestamp我看到了这个!试试这个:

while (!feof($file_handle)) {
        $loansinfo = fgetcsv($file_handle);
        if($loansinfo[0]==$ID){
                $FromDate = "$loansinfo[5]";
                $ToDate ="$loansinfo[6]";
                if (strtotime($DateBorrowedFrom) <= strtotime($WantedDate)) {
                    if(strtotime($ToDate) >= strtotime($WantedDate)){
                        $CantBook = True;
                        }
                }
                else {
                    if (strtotime($DateBorrowedFrom)  <= strtotime($DateTo)) {
                        $CantBook= true;
                        }
                    }
                }
            }
        fclose($file_handle);

        if($CantBook = true){
            echo('<script type="text/javascript">alert("Game is already Booked");</script>');
            }
        else{
    //Saving the booking
while(!feof($file_handle)){
$loansinfo=fgetcsv($file\u handle);
如果($loansinfo[0]=$ID){
$FromDate=“$loansinfo[5]”;
$ToDate=“$loansinfo[6]”;
if(strotime($datebrookedfrom)=strotime($WantedDate)){
$CantBook=True;
}
}
否则{

如果(strotime($datebrookedfrom)可能重复,昨天围绕同一用户“学生”提出的同一问题进行了很长时间的讨论那已经结束了。@bub我已经非常努力地指出了这个问题,并解决了昨天我问我的代码的一个问题,即如何防止在我试图计算返回日期时删除我的表单。我研究了java脚本并找到了解决方法。java脚本并没有在这里发布,因为它与问题无关。我我在这方面做得相当扎实,希望你能在这里看到研究结果,更清楚地了解如何解决原始问题。上传一个csv文件样本…哇,巧合..我刚刚试过,然后看到了这篇文章。我想你已经找到了答案…这肯定是一个重大改进。ISBEVER设置好了,但没有做任何事情。我想知道是不是日期转换导致了这个问题。我使用了一些java脚本,事情可能会变得一团糟。