gamma911 Posted November 14, 2008 Share Posted November 14, 2008 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 https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/ Share on other sites More sharing options...
Mchl Posted November 14, 2008 Share Posted November 14, 2008 if ($current_day = "Tuesday" && $current_time >= 16) { should be if ($current_day == "Tuesday" && $current_time >= 16) { same for other ifs Link to comment https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690080 Share on other sites More sharing options...
gamma911 Posted November 14, 2008 Author Share Posted November 14, 2008 Sorry can you check your reply? the code is the same? Link to comment https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690083 Share on other sites More sharing options...
Mchl Posted November 14, 2008 Share Posted November 14, 2008 Look closer Link to comment https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690084 Share on other sites More sharing options...
gamma911 Posted November 14, 2008 Author Share Posted November 14, 2008 so double = for all ifs? Link to comment https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690086 Share on other sites More sharing options...
Mchl Posted November 14, 2008 Share Posted November 14, 2008 Yes. == means compare = means assign Also, you might want to take a look at switch Link to comment https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690087 Share on other sites More sharing options...
gamma911 Posted November 14, 2008 Author Share Posted November 14, 2008 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 https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690091 Share on other sites More sharing options...
Mchl Posted November 14, 2008 Share Posted November 14, 2008 $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); Link to comment https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690092 Share on other sites More sharing options...
DarkerAngel Posted November 14, 2008 Share Posted November 14, 2008 //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 https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690095 Share on other sites More sharing options...
Mchl Posted November 14, 2008 Share Posted November 14, 2008 I just put random date I figure, that gamma911 can change it to whatever he wants Link to comment https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690097 Share on other sites More sharing options...
gamma911 Posted November 14, 2008 Author Share Posted November 14, 2008 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 https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690098 Share on other sites More sharing options...
DarkerAngel Posted November 14, 2008 Share Posted November 14, 2008 Have you tried the code I gave you? //Get the current hour $current_time = date(G, 1227054540); //Get the current day $current_day = date(l, 1227054540); ??? Link to comment https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690105 Share on other sites More sharing options...
gamma911 Posted November 14, 2008 Author Share Posted November 14, 2008 Yes I have - still displays Monday. When it should display Tuesday? Link to comment https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690110 Share on other sites More sharing options...
DarkerAngel Posted November 14, 2008 Share Posted November 14, 2008 Yes I have - still displays Monday. When it should display Tuesday? *cough* all your comparison need == Yes. == means compare = means assign Also, you might want to take a look at switch Link to comment https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690114 Share on other sites More sharing options...
thebadbad Posted November 14, 2008 Share Posted November 14, 2008 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 https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690132 Share on other sites More sharing options...
xcoderx Posted November 15, 2008 Share Posted November 15, 2008 check this <?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 https://forums.phpfreaks.com/topic/132694-help-display-a-message-according-to-time-of-day/#findComment-690616 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.