Comparison of PHP dates - dd/mm/yyyy

Asked

Viewed 1,329 times

1

I’m looking to do a PHP date comparison of the type: if Datastart >= Datatoday + 3 days, do such a thing. Otherwise, do nothing. I tried something like this:

if ((1/86400)*(strtotime($_SESSION['buscaReserva']['dataInicio'])-strtotime(date("d/m/Y"))))>=3) {
   // Do something }
else {
   // Do nothing }

Both dates are initially in dd/mm/YYYY format. But maybe I can have today’s date in YYYY-mm-dd format. So I may have to do more than one date conversion. For example, 23/06/2015 or 2015-06-23 (today) should be at least three days less than the date of my SESSION (26/06/2015, for example).

HOW DO I DO?

1 answer

-1

You have to add three more days to the current date to make that comparison:

$data = $_SESSION['buscaReserva']['dataInicio'];
$hoje = date("Y-m-d");

$data = strtotime($data);
$hojeMaisTres = date('Y-m-d',strtotime($date . "+3 days"));

if ($data > $hojeMaisTres) {
    // Do something
} else {
    // Do nothing
}
  • Thank you. I’ll look here.

  • You got it working?

  • I don’t know if it’s going very well. I put it in place of Do Something and Do Nothing: echo "Correct" and echo "Wrong". But it’s always going "Wrong". I mean, something in the job isn’t right yet.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.