debugging - PHP Dates: Syntax Debug on PHP if conditional -


in following code $start start date manually entered datepicker , $end separate key also, entered via datepicker. these being compared against date('ymd'), today.

early in code plugin have code (where same argument returns true):

//parse end date if($end):     $end = explode('-', $end);     $end = mktime($hour, $_post['_date_minute'], 0, $end[0], $end[1], $end[2]);         if ((date('ymd',$start) < date('ymd',$end)) && (date('ymd',$end) >= date('ymd'))) {             $compare = date('ymd'); //overwrite start date $compare         }         else {             $compare = date('ymd', $start);                  } endif; 

later in code, same argument returns false here:

function event_list_date($start_or_end, $format, $echo = true){     global $post;      // check end date, if it's greater today , start date less or equal today, round off it's today , doesn't event past      // original code     //  if ((date('ymd',$start) < date('ymd',$end)) && (date('ymd',$end) >= time('ymd'))) {      // stackoverflow proposed change     //  if ($start < $end && $end >= time('ymd')) {      if ($start < $end && $end >= time('ymd')) {         $start = date('ymd'); //overwrite start date $compare     }     else {         $start = get_post_meta($post->id, '_date_start', true);;                 }      $end = get_post_meta($post->id, '_date_end', true);      if($start_or_end == 'start'):         $date = date($format, $start);         if($echo): echo $date; else: return $date; endif;     elseif($start_or_end == 'end'):         $date = date($format, $end);         if($echo): echo $date; else: return $date; endif;     endif;    } 

can tell me why if statement returning false event $start value equal yesterday , $end equal 5 days now?

edit: posting "zoomed out" context of code

the date function changes these strings. you're using mathematical comparison operators compare strings, not work in way you're wanting. if want compare date against date, you'll want convert them more compared, numbers.

strtotime take care of that! since you're passing $start date() (which requires numeric argument), assume $start numeric time representation. so, compare against right now, use time();

strtotime docs

date docs


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -