comparer deux DateTime - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of comparer deux DateTime.php

  1. <?php
  2.  
  3.  
  4. $str = "27.08.2019";
  5. $tab = explode(".",$str);
  6. $timestamp = mktime(0,0,0,$tab[1],$tab[0],$tab[2]);
  7.  
  8. $dateDuJour = new DateTime();$dateDuJour->setTimestamp(time());
  9. echo $dateDuJour->format("d/m/Y")."\n";
  10.  
  11. $maDate = new DateTime();
  12. $maDate->setTimestamp($timestamp);
  13. echo $maDate->format("d/m/Y");
  14.  
  15. if($maDate<$dateDuJour) exit('Trop vieux');
  16. if($maDate >= $dateDuJour) exit('Ok');
  17.  
  18. ?>
  19.  
File Description
  • comparer deux DateTime
  • PHP Code
  • 30 Aug-2019
  • 393 Bytes
You can Share it: