1

I have a table with a date column, the date column has one row for each day in a 10 years period.

Like this:

screenshot of table

I just discovered that the 25th March in 2018 is missing.... as seen on screenshot.

I need to check in an efficient way no more days are missing. I have rows with dates until 31st December 2027.

The dates I inserted in the database with a function in php, then I inserted into the table:

    function dates_between($startdate, $enddate, $format=null){
    (is_int($startdate)) ? 1 : $startdate = strtotime($startdate);
    (is_int($enddate)) ? 1 : $enddate = strtotime($enddate);

    if($startdate > $enddate){
    return false; //The end date is before start date
    }
    while($startdate < $enddate){
    $arr[] = ($format) ? date($format, $startdate) : $startdate;
    $startdate += 86400;
    }
    $arr[] = ($format) ? date($format, $enddate) : $enddate;
    return $arr;
    }
    $fecha1 = $from;
    $fecha2 = $until;

    $data = dates_between($fecha1, $fecha2, 'Y-m-d');
    foreach ($data as $cal_date) {
    $sql = $dbh->prepare ("insert into table.`$property`(cal_date)" ."VALUES (:cal_date)");$sql->execute(array('cal_date' => $cal_date));}
Helenp
  • 143
  • 2
  • 15

0 Answers0