Jump to content

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.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.