Closed (fixed)
Project:
Drupal core
Version:
6.x-dev
Component:
block.module
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
13 Oct 2008 at 14:21 UTC
Updated:
9 Aug 2020 at 11:31 UTC
Jump to comment: Most recent
Comments
Comment #1
BassistJimmyJam commentedUsing PHP, you can get the current time and return true if it is a valid time to display the block. For example, let's say that your program is on the air from 6:00 am - 1:00 pm, you could use the following in your evalutaion:
In this example, if it is 12:13 pm, $current_time will be set to 1213, and the block will be displayed. If the current time is 4:15 am, $current_time will be 415 and the block will not be displayed.
Comment #2
nikemen commentedExcelent... but, how can I do to show the block during specified time but just on tuesdays?
Thanks very much!
Comment #3
dave reidThat would be something like:
Of course adjust the time 'hour' values to when your show is on the air.
Comment #4
BassistJimmyJam commentedYou could also use the following if you prefer a numerical representation:
Checkout out date() in the php manual for for more information on the different formats you can use (http://us2.php.net/manual/en/function.date.php).
Comment #5
BassistJimmyJam commentedNo activity in over two weeks, closing.
Comment #6
tjjacobsen commentedIn the slim chance that someone may still check this thread, I have a follow-up question:
What you show is great, but I have a slightly different need:
I need to also show the block only during certain time periods, however, mine are based on a date field within a Drupal table (specifically, I want a 'reminder' block to show when a user's Ubercart Role expiration date is approaching)
The field would be uc_roles_expirations.expiration, which is turn linked to users.uid by uc_roles_expirations.uid
I suppose I would just need to know how to pull that expiration field value into the calculation.
Any thoughts out there?
thanks!
Comment #7
dotidentity commented-edit-
It is working for me know.
Comment #8
wwwoliondorcom commentedHi,
Do you know any module to do the same job ?
Thanks a lot.
Comment #9
pinkcoffee commentedHello people. Some help needed on this issue. I'm using this kind of php snippets on a D7 website, to make a block on the homepage to change at certain times every weekdays and to load a different one on Sunday.
I used codes like these:
for weekdays
and
for Sunday.
Now, everything works fine during weekdays, but on Sunday I keep seeing both the Sunday block and the ones of weekdays... what could be the problem?
Thanks for support!!
Comment #10
nevets commentedInstead of
try
Also, in the future, please post new issues in a more appropriate forum (probably post installation).
Comment #11
leobaker commentedI am using this code.
$time = (int) date('Gi');
return (date('D') == ('Mon' || 'Tue' || 'Wed' || 'Thu' || 'Fri' || 'Sat' || 'Sun') && $time >= 0001 && $time <= 0359);
As soon as my code hits Midnight 0000 it does not show. What am I doing wrong?
Comment #12
manoloka commentedmy mistake