-2

I am trying to get data from some particular range of dates,

<?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;
    }
        
}

if date range is more then 6 months, then need to call this curl with start and end date, I am trying to insert the startdate and end date in the url.

Kindly help me out to pass the dates in the url.

Thanks in advance

Richard Muvirimi
  • 639
  • 9
  • 14
Aditya
  • 1
  • The code you have shared raises a Syntax Error. If you do not see errors, consider [displaying them](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) while developing. – El_Vanja Apr 13 '21 at 11:52

1 Answers1

0

Replace this :

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

By this :

$curl = 'https://localhost:9200/studio-' . $strStart . ',studio-' . $strEnd . '/_search?pretty';
Maxime D
  • 131
  • 1
  • 6
  • Thank you so much Maxime, if we want wild search after $strStart and $strEnd like studio-2021-02*, studio-2021-03*, then how to change to wild search? – Aditya Apr 13 '21 at 11:44
  • If my answer to your question helped you, please validate it with the gray check mark on the left. You want to calculate the month difference between 2021-02 and 2021-03 without the days, right? – Maxime D Apr 13 '21 at 11:49
  • @Aditya I don't know if it is possible to make a wildcard but I found this if it can help you: https://stackoverflow.com/questions/23126991/month-difference-between-two-dates-yyyymm-format – Maxime D Apr 13 '21 at 11:59