Jump to content

Strtotime Issues


BigEL

Recommended Posts

I'm pretty new to PHP and so far i've written a function to echo the next game in a schedule. Problem is, I want to display "Today" if there is a game today. Currently if today's date = $today, nothing gets displayed frown.gif . I've tried an elseif statement inside the foreach, but with no results.

 

If anyone could point me in the right direction, that be great. Thanks.

 

function next_game(){
$schedule = array(
'vs. team1 ' => strtotime('17 Dec 2012'),
'vs. team2 ' => strtotime('19 Dec 2012'),
'@team3 ' => strtotime('22 Dec 2012'),
'@team4 ' => strtotime('4 Jan 2012')
);


$today = time();// current timestamp[/background][/size][/font][/color]


foreach($schedule as $place => $date){
if($date > $today) {
echo date('M dS', $date)."<small>".$place."</small>";
break;
}
}
}

 

Output

Dec 23rd<small>@FGC </small>
Link to comment
https://forums.phpfreaks.com/topic/272299-strtotime-issues/
Share on other sites

What code did you try? I'm sure it just needs a small change to make it work.

 

[edit] Actually I can guess. $today will be this very second, not just "today". Everything in $schedule will be the same too: you didn't specify a time so one will get filled in for you. So rather than compare $date with $today, compare date("Y-m-d", $date) with date("Y-m-d", $today).

Link to comment
https://forums.phpfreaks.com/topic/272299-strtotime-issues/#findComment-1400945
Share on other sites

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.