The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Time dependant image and text

  • This topic is empty.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
  • #28841

    I am trying to insert an image and some text at different times of the day.

    "image1.png" + "Lorem ipsum" from 12pm to 8am
    "image2.png" + "dolor sit amet" from 8am to 1pm
    "image3.png" + "Pellentesque habitant" from 1pm to 4pm
    "image1.png" + "Lorem ipsum" from 4pm to 12pm

    Does anyone know of a way to do this?

    Rob MacKay

    you could do something simple like this:

    “image1.png”, “txt” => “Lorem ipsum”);
    case 09:
    case 10:
    case 11:
    case 12:
    case 13:
    $dets = array(“img” => “image2.png”, “txt” => “dolor sit amet”);
    case 14:
    case 15:
    case 16:
    $dets = array(“img” => “image3.png”, “txt” => “Pellentesque habitant”);
    case 17:
    case 18:
    case 19:
    case 20:
    case 21:
    case 22:
    case 23:
    case 24:
    $dets = array(“img” => “image1.png”, “txt” => “Lorem ipsum”);

    echo “$dets[txt]“;

    basically gets the date "now" you extract the hour and put it through a switch. I created an array just coz it was easier to store the stuff.

    Edit: the hours are obviously in 24hr format…


    Thanks I’ll try that.

    BTW where is it taking the time from? the local client or the server?
    I would prefer it took the time from the server, and also that the timezone be UTC. That way everyone would get the same result no matter where in the world they are.

    Missed something:
    I forgot to say that I want to specify the images and text per day also. Perhaps I should clearify what I want to use this for.
    I want to show when the phones at our office are open, when there’s a chance of waiting time, and when they are closed.

    green.png "Phones are open"
    Mon-thu 8am-4pm (24H: 08:00-16:00)
    fri 8am-3.30pm (24H: 08:00-15:30)
    Waiting time
    yellow.png "Phones are open. Expect waiting time"
    Mon-fri 1pm-3pm (24H: 13:00-15:00)
    red.png "Pones are closed"
    Rest of the time

    Rob MacKay

    time is taken from the server and it is relative to a UTC date – its "Unix timestamp (the number of seconds since January 1 1970 00:00:00 UTC)" so its UTC by default :)


    Thank you, it works perfect! :)

    Well almost anyway… I don’t know If you saw my last edit, but I also need to specify per weekday, and per minute (08:00-15:30).
    How would you go about that?

    PS Sorry if some of the questions are dumb – I’m still a noob when it comes to php ;)

    Rob MacKay

    yes now you are getting into a bit more time coding wise… I don’t have the time to spend on it unfortunately – I was hoping you could get inspired :D

    you might find this useful… as you pass the timestamp through the date function – you can pretty much pull everything out of it.


    No problem… I’ll check out the php manual and see what I can find out.

    Thanks for your help anyway! :)

    Rob MacKay

    No probs – let us know how you get on – we might be able to keep pointing you in the right direction if you get stuck :)


    Just wanted to check back with an update on this.

    I got some help from a friend, and also the good folks at stckoverflow, and ended up with this solution.

Viewing 9 posts - 1 through 9 (of 9 total)
  • The forum ‘Back End’ is closed to new topics and replies.