Show PHP Content during time range for specific day of the week

I’m trying to design a script that shows specific content on a weekly basis. For example

Monday: Content A
Tuesday: Content B
Wednesday: Content C
Thursday: Content D
Friday: Content E
Saturday: Content F
Sunday: Content G

Aside from that I need to ensure that using the server time, instead of changing at Midnight (like it normally would if time was not a factor), that it changes once the server time hits 02:30:00AM. I have attempted to do this myself, several times but ended up scrapping all of my code because of errors, or because it was not working properly. So I’m basically starting from scratch. If someone can show me how to do one day, I can do the rest of it, I just can’t figure out why I’m not able to make it change after a certain time.

Help would be greatly appreciate as I’ve been working on this since last week and I’ve still not gotten anywhere, and posts from other websites have just further confused me.

Lots of ways to do this

One way is just to create a DateTime-object for the current time, then subtract 2,5 hours. It effectively makes the check run until 02:30 am :slight_smile:
[php]<?php
date_default_timezone_set(‘Europe/Oslo’);

$time = new DateTime();
$time->sub(date_interval_create_from_date_string(‘2 hours 30 minutes’));

switch ($time->format(‘l’)) {

case ‘Sunday’:
echo ‘do stuff for sunday!’;
break;

case ‘Monday’:
echo ‘do stuff for monday!’;
break;

case ‘Tuesday’:
echo ‘do stuff for tuesday!’;
break;

case ‘Wednesday’:
echo ‘do stuff for wednesday!’;
break;

case ‘Thursday’:
echo ‘do stuff for thursday!’;
break;

case ‘Friday’:
echo ‘do stuff for friday!’;
break;

case ‘Saturday’:
echo ‘do stuff for saturday!’;
break;
}[/php]

Depending on what you’re actually going to do some other solution might be preferred :slight_smile:

This site is absolutely amazing. I’ve been looking for this solution for longer than I can remember, and have actively been trying to resolve it for 2 weeks.

Thank you so much! Maybe I should try seeing if I can get my other problems solved here too :slight_smile:

Bring it :smiley:

btw: you can find your local time zone here http://php.net/manual/en/timezones.php

Sponsor our Newsletter | Privacy Policy | Terms of Service