1

Can someone give me a working example of what my code should be as my efforts are getting me nowhere?

My code currently says have

if (isset($_POST['startdate'])) {
    $startdate = DatePickerToTime($_POST['startdate']);
} else { 
    $startdate = strtotime('today midnight');
}

and

if (isset($_POST['enddate'])) { 
    $enddate = DatePickerToTime($_POST['enddate']);
} else { 
    $enddate = time();
}

which works.

However, I want to say if startdate is equal to enddate then add 23 hours and 59 minutes to enddate

I have read the documentation and am trying

if($_POST['$startdate'] == $_POST['$enddate']) {
    $_POST['$enddate'] += date("h:i:sa", "23:59:59");
}

but this doesn't work.

common sense
  • 3,775
  • 6
  • 22
  • 31
ginomay89
  • 249
  • 3
  • 17
  • 1
    check the documentation again, the 2nd param of [date()](http://php.net/manual/en/function.date.php) is an int, so passing `"23:59:59"` wouldn't work. Rather than adding 23hours, 59minutes and 59seconds, could you go down this route `strtotime('tomorrow midnight -1 second')`? – SubjectCurio Nov 15 '18 at 08:57

1 Answers1

2
$datetime1 = date('2009-10-11 12:30:00');
$datetime2 = date('2009-10-11 12:30:00');
echo "<pre>";
if($datetime1 == $datetime2){
    echo "yes";
    echo "<br>";
    $datetime2 = date("Y-m-d H:i:s", strtotime("+23 hours 59 minutes",strtotime($datetime2)));
    echo $datetime1."===================".$datetime2;
}
else {
    echo "NO<br>";
    echo $datetime1."===================".$datetime2;
}
Atmiya Kolsawala
  • 475
  • 4
  • 12