PHP how to check current DateTime and future DateTime until difference becomes 0


Is it possible to check current DateTime and future DateTime in every 30 seconds until difference becomes 0 ( current DateTime to be equal to the future DateTime ) with precision of a minute using PHP ? My code is not continuously in every 30 seconds:

  $dt_format = 'Y-m-d H:i';

  $new_row = "<br>";

  $dt_now = new DateTime();
  $date1 = DateTime::createFromFormat($dt_format, '2016-09-01 14:00');
  $date2 = DateTime::createFromFormat($dt_format, '2016-09-01 14:15');

  print("Today is " . $dt_now->format($dt_format) . $new_row);

  $diff1 = $dt_now->diff($date1);
  print ($diff1->format('%y years %m months %d days %h hours %i minutes') . $new_row);

  $diff2 = $dt_now->diff($date2);
  print ($diff2->format('%y years %m months %d days %h hours %i minutes') . $new_row);



Do you want to block the page load into the time matches? That will lead to resource exhaustion on your server if the target time is too long.

PHP is single threaded so you can't do this check in the background.

Better to write out a holding page for the user, which tries to reload every 30 seconds.

If the time is reached, show the content, otherwise show a page with this content:

<p>Please wait until (put target time)</p>
     setTimeout(function() {
     }, 30000);

People are also looking for solutions to the problem: php - using select2 in a prestashop module


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.