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

Edited by requinix
Link to comment
Share on other sites

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.