Jump to content

help display a message according to time of day.


gamma911

Recommended Posts

HI there

 

I would like to display a message according to the time of day, ( to coincide with a deadline of 4pm Tuesday)

so if it is

Monday = monday

Tuesday before 4pm = Tuesday

Tuesday after 4pm = tuesday after 4pm

Wednseday = wednesday

Thursday = Thursday

Friday = friday

Saturday = saturday

Sunday = sunday

 

Totally stumped as the code always returns monday

 

{php}
	putenv('TZ=Europe/London');		
	echo date('l jS \of F Y h:i:s A'); 
	?><br /><?

$monday = "monday";
$tuesday = "tuesday before 4";
$tuesdayafterfour = "tuesday after 4";
$wednesday = "wednesday ";
$thursday = "thursday ";
$friday = "friday ";
$saturday ="saturday";
$sunday ="sunday";


//Get the current hour
$current_time = date(G);
//Get the current day
$current_day = date(l);


if  ($current_day = "Tuesday" && $current_time >= 16) {
echo $tuesdayafterfour;
}

elseif ($current_day = "Monday") {
echo $monday;
}	

elseif ($current_day = "Tuesday") {
echo $tuesday;
}	

elseif ($current_day = "Wednesday") {
echo $wednesday;
}	

elseif ($current_day = "Thursday") {
echo $thursday;
}	

elseif ($current_day = "Friday") {
echo $friday;
}	

elseif ($current_day = "Saturday") {
echo $saturday;
}	

elseif ($current_day = "Sunday") {
echo $sunday;
}	

{/php}

 

Any ideas will be great

Link to comment
Share on other sites

Sorry I'm super new when it comes to php.

		{php}
	putenv('TZ=Europe/London');		
	echo date('l jS \of F Y h:i:s A'); 
	?><br /><?
	//Change the messages to what you want.
$monday = "monday";
$tuesday = "tuesday before 4 ";
$tuesdayafterfour = "tuesday after 4";
$wednesday = "wednesday ";
$thursday = "thursday ";
$friday = "friday ";
$saturday ="satur";
$sunday ="sunday";

//No need to edit any further

//Get the current hour
$current_time = date(G);
//Get the current day
$current_day = date(l);

//12 p.m. - 4 p.m.
if  ($current_day == "Tuesday" && $current_time >= 16) {
echo $tuesdayafterfour;
}
//If it's Friday, display a message
elseif ($current_day == "Monday") {
echo $monday;
}	
//If it's Friday, display a message
elseif ($current_day == "Tuesday") {
echo $tuesday;
}	
//If it's Friday, display a message
elseif ($current_day == "Wednesday") {
echo $wednesday;
}	
//If it's Friday, display a message
elseif ($current_day == "Thursday") {
echo $thursday;
}	
//If it's Friday, display a message
elseif ($current_day == "Friday") {
echo $friday;
}	
//If it's Friday, display a message
elseif ($current_day == "Saturday") {
echo $saturday;
}	
//If it's Friday, display a message
elseif ($current_day == "Sunday") {
echo $sunday;
}	

{/php}

 

That does now display Friday - but is it possible to change the time on the server for this statement to see if Tuesday 4pm will work?

Link to comment
Share on other sites

//Get the current hour
$current_time = date(G, 1227054540);
//Get the current day
$current_day = date(l, 1227054540);

the timestamp "1227054540" is next tuesday @ 6:29PM

$time = strtotime("12-10-2008 15:47");
//Get the current hour
$current_time = date(G,$time);
//Get the current day
$current_day = date(l,$time);

Thats a wednesday lol before 4PM at that
Link to comment
Share on other sites

Thanks but it's still not working right.

$monday = "monday";
$tuesday = "tuesday before 4 ";
$tuesdayafterfour = "tuesday after 4";
$wednesday = "wednesday ";
$thursday = "thursday ";
$friday = "friday ";
$saturday ="satur";
$sunday ="sunday";

//No need to edit any further

//Get the current hour
$time = strtotime("13-10-2008 15:47");
$current_time = date(G,$time);
//Get the current day
$current_day = date(l,$time);

//12 p.m. - 4 p.m.
if  ($current_day == "Tuesday" && $current_time >= 16) {
echo $tuesdayafterfour;
}
//If it's Friday, display a message
elseif ($current_day = "Monday") {
echo $monday;
}	
//If it's Friday, display a message
elseif ($current_day = "Tuesday") {
echo $tuesday;
}	
//If it's Friday, display a message
elseif ($current_day = "Wednesday") {
echo $wednesday;
}	
//If it's Friday, display a message
elseif ($current_day = "Thursday") {
echo $thursday;
}	
//If it's Friday, display a message
elseif ($current_day = "Friday") {
echo $friday;
}	
//If it's Friday, display a message
elseif ($current_day = "Saturday") {
echo $saturday;
}	
//If it's Friday, display a message
elseif ($current_day = "Sunday") {
echo $sunday;
}	

{/php}

 

With that code and date its displaying Monday.

Link to comment
Share on other sites

You also forgot quotes around some date() parameters. switch() approach:

 

{php}

putenv('TZ=Europe/London');
echo date('l jS \of F Y h:i:s A') . '<br />';

switch(date('l')) {
case 'Monday':
	echo 'Monday';
	break;
case 'Tuesday':
	if (date('G') >= 16) {
		echo 'Tuesday after 4';
	} else {
		echo 'Tuesday before 4';
	}
	break;
case 'Wednesday':
	echo 'Wednesday';
	break;
case 'Thursday':
	echo 'Thursday';
	break;
case 'Friday':
	echo 'Friday';
	break;
case 'Saturday':
	echo 'Saturday';
	break;
case 'Sunday':
	echo 'Sunday';
	break;
}

{/php}

Link to comment
Share on other sites

check this  ;D

<?php

$TimeZone="8"; ////Change the TimeZone accordingly!
$New_Time = time() + ($TimeZone * 60 * 60);

$show_date=date("D dS F, Y",$New_Time); 
$show_time=date("H:i",$New_Time); 
$Hour=date("G",$New_Time);

echo $show_date;
echo"<br/>";
echo $show_time;
echo"<br/>";

////////////////////////////////////////
//Here you can change the messages/////
//add lines with different hours etc// 
//You could even display a different/
////////message every hour./////////

if ($Hour <= 4) { echo 'Hello Night Rider'; } 

else if ($Hour <= 11) { echo 'Good morning'; } 

else if ($Hour <= 12) { echo 'Enjoy your lunch!'; }

else if ($Hour <= 17) { echo 'Good afternoon'; } 

else if ($Hour <= 23) { echo 'Good Evening'; }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.