The time, one timezone east, is <?php InsertTime(+1,"SHORT"); ?>.InsertTime( offset, format )
<?php //----------------------------------------------------- // InsertTime() // - - - - - - // Prints the current time. // // $offset - Hours difference between the displayed // time and the web server's time. // $format - "SHORT" or "LONG". //----------------------------------------------------- function InsertTime($offset=0, $format="long") { $kHour = 60*60; if( strcasecmp($format,"long") == 0 ) print date("g:i:s A",time()+$offset*$kHour); else print date("g:i A",time()+$offset*$kHour); } ?>
<?php if( ShowTime("15:0 15:1 15:2") ) { ?>
This text is displayed from 3:00:00 pm to 3:29:59 pm.
<?php } ?>
ShowTime( times )
<?php
//-----------------------------------------------------
// ShowTime($times)
// - - - - - - - -
// This function will return true if the current time
// is specifed in the parameters.
//
// $times - a string in the format "time1 time2 ..."
// where time# is in the format "H[:i[:s]]"
//
// Example: ShowTime("08:3") returns true if the time
// is 8:30:00 am - 8:39:59 am
//-----------------------------------------------------
function ShowTime( $times )
{
if( !is_array($times) )
$times = explode(" ",trim($times));
while( $time = each($times) )
{
$t = trim($time[value]);
if( strlen($t) == 1 )
$t = "0".$t;
if( strlen($t) > 0 )
if( strcmp($t,substr(date("G:i:s"),0,strlen($t))) == 0 ||
strcmp($t,substr(date("H:i:s"),0,strlen($t))) == 0 )
return true;
}
return false;
}
?>
<?php if( HideTime("11") ) { ?>
This text is hidden from 11:00:00 am to 11:59:59 am.
<?php } ?>
HideTime( times )
<?php
//-----------------------------------------------------
// HideTime($times)
// - - - - - - - -
// Returns false if the current time is specified in
// the parameters.
//
// See: ShowTime().
//-----------------------------------------------------
function HideTime( $times ) {
return !ShowTime($times);
}
?>
The date, three timezones west, is <?php InsertDate(-3,"LONG"); ?>.InsertDate( offset, format )
<?php //----------------------------------------------------- // InsertDate() // - - - - - - // Prints the current date. // // $offset - Hours difference between the displayed // date and the web server's date. // $format - "SHORT" or "LONG". //----------------------------------------------------- function InsertDate($offset=0, $format="long") { $kHour = 60*60; if( strcasecmp($format,"long") == 0 ) print date("l, F j, Y",time()+$offset*$kHour); else print date("m/d/y",time()+$offset*$kHour); } ?>
<?php if( ShowDate("8/7/00@11:41","8/12/00") ) { ?>
This text is displayed after 7 Aug 2000 @ 11:41 but before 12 Aug 2000.
<?php } ?>
ShowDate( begin, end )
<?php
//-----------------------------------------------------
// ShowDate($begin,$end)
// - - - - - - - -
// Returns true if the current date and time is after
// or including $begin and before $end.
//
// Both $begin and $end should be formatted as:
// "m/d/y[@H[:i[:s]]]"
//
// If $begin equals 0 or "*", the function returns true
// if the current date is before $end.
//
// If $end equals 0 or "*", the function returns true
// if the current date is after $begin.
//
//
// Example: ShowDate("1/1/00","1/1/01") returns true
// during the year 2000.
//-----------------------------------------------------
function ShowDate( $begin, $end = 0 )
{
if( $end == 0 )
{
$list = explode(" ",trim($begin));
$begin = $list[0];
$end = $list[sizeof($list)-1];
if( $end == "" )
$end = 0;
}
$list = array( "begin", "end" );
while( list($key,$value) = each($list) )
{
if( is_string( $$value ) && strcmp($$value,"*") != 0 )
{
list($date,$time) = explode("@",$$value);
list($month,$day,$year) = explode("/",$date);
list($hour,$min,$sec) = explode(":",$time);
$$value = mktime($hour,$min,$sec,$month,$day,$year<80 ? 2000+$year : $year);
}
else if( is_string( $$value ) && strcmp($$value,"*") == 0 )
$$value = 0;
}
return( $begin <= time() && ($end == 0 || time() < $end) );
}
?>
<?php if( HideDate("8/1/00","8/7/00") ) { ?>
This text is hidden between 1 Aug 2000 and 7 Aug 2000.
<?php } ?>
HideDate( begin, end )
<?php
//-----------------------------------------------------
// HideDate($begin,$end)
// - - - - - - - -
// Returns false if the $begin <= current date < $end.
//
// See: ShowDate().
//-----------------------------------------------------
function HideDate( $begin, $end )
{
return !ShowDate($begin,$end);
}
?>
<INSERT_COUNTDOWN_WDHM date@time "Weeks" "Days" "Hours" "Minutes">
The New Year is in <?php InsertCountdown("1/1/".(date("Y")+1)); ?>.
InsertCountdown( Date@Time )
<?php
//-----------------------------------------------------
// InsertCountdown($dateTime)
// - - - - - - - -
// Prints the number of weeks, days, hours, and minutes
// between the current time() and $dateTime.
//
// $dateTime should be formatted as:
// "m/d/y[@H[:i[:s]]]"
//
// Example: Countdown to Halloween Festivities!
// InsertCountdown("10/31/2000@19:30")
//-----------------------------------------------------
function InsertCountdown( $dateTime, $sWeek = "Week",
$sDay = "Day",
$sHour = "Hour",
$sMin = "Minute",
$sSec = "" )
{
print Countdown( $dateTime, $sWeek, $sDay, $sHour, $sMin, $sSec );
}
Countdown( Date@Time )
//-----------------------------------------------------
// Countdown($dateTime)
// - - - - - - - -
// Returns a string representing the difference between
// the current time and the input time.
//
// $dateTime should be formatted as:
// "m/d/y[@H[:i[:s]]]"
//
// Example: Countdown to Halloween Festivities!
// InsertCountdown("10/31/2000@19:30")
//-----------------------------------------------------
function Countdown( $dateTime, $sWeek = "Week",
$sDay = "Day",
$sHour = "Hour",
$sMin = "Minute",
$sSec = "" )
{
$kSec = 1;
$kMin = 60*$kSec;
$kHour = 60*$kMin;
$kDay = 24*$kHour;
$kWeek = 7*$kDay;
list($date,$time) = explode("@",$dateTime);
list($month,$day,$year) = explode("/",$date);
list($hour,$min,$sec) = explode(":",$time);
$inTime = mktime($hour,$min,$sec,$month,$day,$year<80 ? 2000+$year : $year);
$time_difference = abs(time()-$inTime);
$weeks = ( empty($sWeek) ? 0 : floor($time_difference / $kWeek) ); $time_difference -= $weeks * $kWeek;
$days = ( empty($sDay) ? 0 : floor($time_difference / $kDay) ); $time_difference -= $days * $kDay;
$hours = ( empty($sHour) ? 0 : floor($time_difference / $kHour) ); $time_difference -= $hours * $kHour;
$mins = ( empty($sMin) ? 0 : floor($time_difference / $kMin) ); $time_difference -= $mins * $kMin;
$secs = ( empty($sSec) ? 0 : floor($time_difference / $kSec) );
$out = ( $weeks == 0 ? "" : "$weeks $sWeek" . ($weeks>1?"s":"") );
$out .= ( $days == 0 ? "" : (empty($out)?"":", ") . "$days $sDay" . ( $days>1?"s":"") );
$out .= ( $hours == 0 ? "" : (empty($out)?"":", ") . "$hours $sHour" . ($hours>1?"s":"") );
$out .= ( $mins == 0 ? "" : (empty($out)?"":", ") . "$mins $sMin" . ( $mins>1?"s":"") );
$out .= ( $secs == 0 ? "" : (empty($out)?"":", ") . "$secs $sSec" . ( $secs>1?"s":"") );
print $out;
}
?>
In Action
The New Year is in 6 Weeks, 1 Day, 9 Hours, 6 Minutes.
<INSERT_DAY offset>
Today is <?php InsertDay(); ?>
InsertDay( offset, format )
<?php
//-----------------------------------------------------
// InsertDay()
// - - - - - -
// Prints the day of the week.
//
// $offset - Hours difference between the displayed
// day and the web server's day.
// $format - "SHORT" or "LONG".
//-----------------------------------------------------
function InsertDay($offset=0, $format="long")
{
$kHour = 60*60;
if( strcasecmp($format,"long") == 0 )
print date("l",time()+$offset*$kHour);
else
print date("D",time()+$offset*$kHour);
}
?>
<SHOW_DAY day1 day2 ...>
<?php if( ShowDay("FRI MON") ) { ?>
This text is displayed on Friday and Monday.
<?php } ?>
ShowDay( days )
<?php
//-----------------------------------------------------
// ShowDay($days)
// - - - - - - - -
// Returns true if today is in the list of days.
//
// $days should be formatted:
// "day1 day2 day3 ..."
//
// i.e.:
// "MON TUE WED"
//-----------------------------------------------------
function ShowDay( $days )
{
if( !is_array($days) )
$days = explode(" ",$days);
while( $day = each($days) )
{
$d = trim($day[value]);
if( strlen($d) > 0 && stristr(date("l"),$d) )
return true;
}
return false;
}
?>
<HIDE_DAY day1 day2 ...>
<?php if( HideDay("TUE THU") ) { ?>
This text is hidden on Tuesday and Thursday.
<?php } ?>
HideDay( days )
<?php
//-----------------------------------------------------
// HideDay($days)
// - - - - - - - -
// Returns false if today is in the list of days.
//
// $day should be formatted:
// "day1 day2 day3 ..."
//
// i.e.:
// "MON TUE WED"
//-----------------------------------------------------
function HideDay( $days )
{
return !ShowDay($days);
}
?>