Jump to content

[SOLVED] Simple date function not responding


cmcdonld

Recommended Posts

This is a simple function to check a date between two dates. It works for anything in the current year, but I want it to roll through 2010 and it fails with the end_date. I would typically write this function in a simpler way, but this was how I tested where it was failing, any suggestions on why it won't check into 2010?

 

<?php
function opendates(){
     $start_date = date("m/d/Y", mktime(0,0,0,11,01,2009)); 
     $end_date = date("m/d/Y", mktime(0,0,0,01,20,2010));  
     $today_date = date("m/d/Y", mktime(0,0,0,date(m),date(d),date(Y)));
     if($today_date >= $start_date) {
if($today_date <= $end_date) {
     echo "Success";
}
else { 
     echo "Failed on 2nd if";
}
     } 
     else { 
          echo "Failed on first if"; 
     }
}
?>

 

Thanks!

You cannot do greater-than/less-than comparisons on dates unless the format can be compared by magnitude. This either requires using a Unix timestamp or the fields making up the date must be ordered left-right Year - month - day and the length of the corresponding field in each value is the same (you need leading zeros.)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.