Php 在url中传递日期

Php 在url中传递日期,php,date,curl,Php,Date,Curl,我试图从某个特定的日期范围获取数据 <?php function index_finder() { $strStart = '2021-01-02'; $strEnd = '2021-08-28'; $dteStart = new DateTime($strStart); $dteEnd = new DateTime($strEnd); $dteDiff = $dteStart->diff($dteEnd);

我试图从某个特定的日期范围获取数据

<?php

function index_finder()
{
     $strStart = '2021-01-02';
     $strEnd   = '2021-08-28'; 
     
     $dteStart = new DateTime($strStart);
     $dteEnd   = new DateTime($strEnd);

    $dteDiff  = $dteStart->diff($dteEnd);
    $date = $dteDiff->format("%m month\n");
    if ($date > 6)
    {
    $curl = 'https://localhost:9200/studio-.'$strStart'.,studio-.'$strEnd'./_search?pretty';
    print $curl;
    }
        
}
替换此:

$curl = 'https://localhost:9200/studio-.'$strStart'.,studio-.'$strEnd'./_search?pretty';
据此:

$curl = 'https://localhost:9200/studio-' . $strStart . ',studio-' . $strEnd . '/_search?pretty';

非常感谢Maxime,如果我们想在$strStart和$strud like studio-2021-02*、studio-2021-03*之后进行野生搜索,那么如何更改为野生搜索?如果我对您问题的回答对您有所帮助,请使用左侧的灰色复选标记验证。您想计算2021-02和2021-03之间的月差(不含天数),对吗?是的,还有通配符搜索also@Aditya我不知道是否可以创建通配符,但如果它能帮助您,我发现了这一点:您共享的代码会引发语法错误。如果你没有看到错误,在开发的时候考虑。