lice200 Posted December 19, 2006 Share Posted December 19, 2006 Hello, I am writing a script (duh) that will take a set time and the current time then within the code it will echo a set link (or whatever i want). However I am having trouble coming up with a way to do it. What I want it to do is when say it is 1030am I want it to echo a link (Set with $link). However if it is 1130am I want it to display different link instead of the other one. (Set with link2). My problem is when it is 1030am it echo's $link, then at 1130am it echo's $link2 at the same time as $link. Can you help me find a way to make it echo only one at a time?[code]<?php $curtime = date('hia'); //Get the current time in format 00:00:am/pm (Without ':') echo "Current Time: $curtime<br>";//Specify the start time and the delay$timestr = "0429pm";$link1 = "Link One";$timestr2 = "0431pm";$link2 = "Link Two";if ($curtime > $timestr) { // Script start. echo "$link1"; } if ($curtime > $timestr2) { echo "$link2";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/31184-specific-start-time-script/ Share on other sites More sharing options...
JasonLewis Posted December 19, 2006 Share Posted December 19, 2006 [code=php:0]} if ($curtime > $timestr2) {[/code]that looks odd. try changing it to this:[code=php:0]}elseif($curtime > $timestr2) {[/code]and try removing the a in the date function, so your just testing against numbers.[code=php:0]$curtime = date('hi'); echo "Current Time: $curtime<br>";//Specify the start time and the delay$timestr = "0429";$link1 = "Link One";$timestr2 = "0431";$link2 = "Link Two";[/code] Link to comment https://forums.phpfreaks.com/topic/31184-specific-start-time-script/#findComment-144134 Share on other sites More sharing options...
btherl Posted December 19, 2006 Share Posted December 19, 2006 And [code=php:0]date('Hi');[/code] will give you 24 hour time, in case you want to do tests that cover both am and pm. If you want your input to use am and pm, then do a conversion to 24 hour time before doing the test. That's easier than trying to compare am/pm time directly. Link to comment https://forums.phpfreaks.com/topic/31184-specific-start-time-script/#findComment-144140 Share on other sites More sharing options...
lice200 Posted December 19, 2006 Author Share Posted December 19, 2006 So I changed my code (Below) and now it is not echo'ing the $timestr2 even though it is past the set time. I changed the date function to Hi instead of hia.[code]<?php //Specify the start time and the delay$timestr = "2333";$link1 = "Link One";$timestr2 = "2334";$link2 = "Link Two";$curtime = date('Hi'); //Get the current time in format 00:00:am/pm (Without ':') echo "Current Time: $curtime<br>"; if ($curtime > $timestr) { // Script start. echo "$link1"; } elseif ($curtime > $timestr2) { echo "$link2";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/31184-specific-start-time-script/#findComment-144250 Share on other sites More sharing options...
lice200 Posted December 20, 2006 Author Share Posted December 20, 2006 Anyone? Link to comment https://forums.phpfreaks.com/topic/31184-specific-start-time-script/#findComment-144971 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.