Riseykins Posted December 23, 2008 Share Posted December 23, 2008 Can someone help me with this? I want to display certain images at certain times of the day, as well as on certain days of the week. How can I do this? Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/138246-how-do-i-get-things-to-show-up-at-certain-times-only/ Share on other sites More sharing options...
Maq Posted December 23, 2008 Share Posted December 23, 2008 You need to manipulate the date() function. G 24-hour format of an hour without leading zeros 0 through 23 This may be helpful as well to check to see if it's day or night: A Uppercase Ante meridiem and Post meridiem AM or PM And a numerical representation of the day of the week: w Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) Quote Link to comment https://forums.phpfreaks.com/topic/138246-how-do-i-get-things-to-show-up-at-certain-times-only/#findComment-722780 Share on other sites More sharing options...
ngreenwood6 Posted December 23, 2008 Share Posted December 23, 2008 you would need a basic IF statement and date() function. here is a basic example: $date = date("m/d/Y") if($date == "12/23/08") { show this image } elseif($date == "12/24/08") { show this image } else { nothing to show } look into the date function, it is capable of doing time and days of the week to check against. Quote Link to comment https://forums.phpfreaks.com/topic/138246-how-do-i-get-things-to-show-up-at-certain-times-only/#findComment-722781 Share on other sites More sharing options...
Riseykins Posted December 23, 2008 Author Share Posted December 23, 2008 Well I am wanting to show an alert on my website at certain times each day. I need it to show up between 2 and 3 am, 10 and 11 am and 2 and 3 pm. I don't really know PHP much at all, so I don't know how to edit much, really. Quote Link to comment https://forums.phpfreaks.com/topic/138246-how-do-i-get-things-to-show-up-at-certain-times-only/#findComment-722786 Share on other sites More sharing options...
ngreenwood6 Posted December 23, 2008 Share Posted December 23, 2008 No one is just going to write it for you but I will help give you a start: $time_now = date("H"); \\puts it in 24 hour formate $ if($time_now == 2 || $time_now == 14) \\if the time is 2 am or pm { echo "It is 2 o'clock!"; } elseif($time_now == 10) { echo "It is 10 am!"; } else { echo "it isn't 10 or 2"; } check out this page on php date http://www.tizag.com/phpT/phpdate.php Quote Link to comment https://forums.phpfreaks.com/topic/138246-how-do-i-get-things-to-show-up-at-certain-times-only/#findComment-722791 Share on other sites More sharing options...
lokie538 Posted December 24, 2008 Share Posted December 24, 2008 Could you use a cron job to change the one picture source? Quote Link to comment https://forums.phpfreaks.com/topic/138246-how-do-i-get-things-to-show-up-at-certain-times-only/#findComment-722914 Share on other sites More sharing options...
Riseykins Posted December 24, 2008 Author Share Posted December 24, 2008 I don't know what a cron job is. Quote Link to comment https://forums.phpfreaks.com/topic/138246-how-do-i-get-things-to-show-up-at-certain-times-only/#findComment-722945 Share on other sites More sharing options...
Maq Posted December 24, 2008 Share Posted December 24, 2008 Could you use a cron job to change the one picture source? You don't need a cron job. The only time someone is going to see it is when they get to the site. So all you need to do is modify ngreenwood's code to fit your needs. Why don't you try it, and if you still can't get it to work, come back with more questions? Usually if you show some effort we're willing to help a lot more. Quote Link to comment https://forums.phpfreaks.com/topic/138246-how-do-i-get-things-to-show-up-at-certain-times-only/#findComment-723163 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.