NewWorldOrderly
NewWorldOrderly

Reputation: 51

How to show only content from days before or equal to today?

i have a pretty simple question and i'm just not sure why the code I have isn't working.

<div id="right_bottom">
<?
list($y, $m, $d) = explode('-', $pagedata->program->start);
foreach($pagedata->program->__workouts as $day => $workout){
   if (date('F j, Y', mktime(0, 0 ,0, $m, $day, $y)) <= date('F j, Y')){
?>
   <div id="right_side">
    <div id="<?=$workout->id?>" class="side_items">
     <a class="workouts" href="<?=$pagedata->program->id?>,<?=$day?>">
     <img src="<?=PROTOCOL?>//<?=DOMAIN?>/img/workout/<?=$workout->image?>"><br />
     <strong><?=$workout->title?></strong></a><br />
     <h2><?=date('F j, Y', mktime(0, 0 ,0, $m, $day, $y))?></h2><br />
   </div>
  </div>

<?
}
}
?>
</div>

i want the IF condition statement to show only the "right_side" DIV for days before or equal to today.

it is currently still showing all days

what am i missing here?

Upvotes: 1

Views: 123

Answers (2)

wyqydsyq
wyqydsyq

Reputation: 2020

You're comparing strings as decimal values, try:

if(strtotime($y.'-'.$m.'-'.$day) <= strtotime('today')){
    // ...
}

Upvotes: 1

Cassie Smith
Cassie Smith

Reputation: 501

I would assume its because you are trying to compare two strings. Try comparing the unix time stamp instead:

if (mktime(0, 0 ,0, $m, $day, $y) <= time()){

Hope this helps!

Upvotes: 3

Related Questions