Posted By

stamba on 10/04/10


Tagged

date compare dates


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

vkolev
bobbym245
luman
korpz


Compare dates using strtotime


 / Published in: PHP
 

  1. // Get the dates
  2. $today = date("m/d/Y");
  3. $datefrom = "10/01/2010";
  4. $dateto = "10/12/2010";
  5.  
  6. // Convert dates to strings
  7. $todaystring = strtotime($today);
  8. $datefromstring = strtotime($datefrom);
  9. $datetostring = strtotime($dateto);
  10.  
  11. // Compare the dates (check if today is between start and end dates)
  12. if ($todaystring >= $datefromstring && $todaystring <= $datetostring) {
  13. // Do something if today is in between
  14. echo "Date is ok.";
  15. } else {
  16. // Do something if it is not in between
  17. echo "Date is wrong.";
  18. }

Report this snippet  

You need to login to post a comment.