Ready to get started?Download WordPress


New TV guide Plugin - Syntax help pls. (6 posts)

  1. vlowe
    Posted 7 years ago #

    Hi i have been working on a daily tv guide plugin for my blog.

    see here:

    its early in dev yet :P

    i just thorght it would be cool to colour whats on now!

    im not too hot on date/time just wondered if anyone could help me out.

    currently i print the date using
    print $Programme['time'];
    that will display something like 4:05pm

    1. if $Programme['time'] = time now , color = yellow
    else normal

    2. if $Programme['time'] = time now +/- 15mins, color = yellow
    else normal

    3. the holy grail! find the last start time before current time!

    that would be great but no idea how to do it.

    any ideas or solutions?

  2. vlowe
    Posted 7 years ago #

    please help someone

    a good start would be how to create a variable of the time now in this format 4:05pm


    any ideas on a time range before and after this time by say 15 mins.

    dont want to use $time -5 as that would just be five mins earlier i need it to be between now and then. if u get me

  3. leflo
    Posted 7 years ago #

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    It's hard to say what to do without seeing your code.

    You'll want to take the time you receive from wherever and convert it to the epoch time. You'll probably use strtotime() to do this. You should also get the next time value to determine the end of the program. Or maybe you have a length value somewhere? Depends on your input data.

    Then you get the current time with time().

    Then you compare the times, and determine whether the program is on now. If it is, I would have it output a special class on the item, like "program_on_now" or something. Then you can use that in the CSS to change the background color. That way, you can change the background colors without changing the code later.

  5. vlowe
    Posted 7 years ago #

    cheers guys,

    i have been playing with it last night.

    i can get the date now:

    so i tried.
    $vdate = date('h:ia');

    if ($Programme['time'] < $vdate){
    print '<font color="#FF0000">'.$aProgramme['time'].'</font>';
    else {
    print $aProgramme['time'];

    i was trying to show started programmes in red.
    this gave inacurate results.

    probably because of the am/pm??

    i would move to 24hr format but the data i fetch is in 12hr with the am/pm attached :(

  6. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    You cannot directly compare two different dates like that. Those are not times, they are *strings*.

    What you have to do is convert both datetimes into a *number*. time() will give you the current time in the form of a number, and you can use strtotime() to convert the Programme[time] into a number as well.

    Once you have them both as *numbers*, then you can compare them and get accurate results. Comparing them as strings will give you the inaccurate results.

Topic Closed

This topic has been closed to new replies.

About this Topic