cmaximus Posted March 25, 2009 Share Posted March 25, 2009 I'm working with this code that is suppose to display when the stock market is open or closed based on the users computer clock, but it's not working, could anyone please tell me what I'm doing wrong... Here's the code: $clock = explode(':',''.$quote[9].''); if ($clock >= "4") { if ($clock == "00pm") { $stat = '<b><font color="red">Closed</font></b>'; } else { $stat = '<b><font color="green">Open</font></b>'; } } else { $stat = '<b><font color="green">Open</font></b>'; } Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 25, 2009 Share Posted March 25, 2009 Where are you getting the clock time from? Quote Link to comment Share on other sites More sharing options...
cmaximus Posted March 25, 2009 Author Share Posted March 25, 2009 That's a good question, I was given this code and thought that all of the clock info was in that code snippet... this part of the code is in the header: $clock = explode(':',''.$quote[9].''); if ($clock >= "4") { if ($clock == "00pm") { $stat = '<b><font color="red">Closed</font></b>'; } else { $stat = '<b><font color="green">Open</font></b>'; } } else { $stat = '<b><font color="green">Open</font></b>'; } and this part of the code is in the body where the display needs to be: <?=$stat// show market status?> The website that I'm trying to implement this is http://www.stockowls.com The market opens at 9:30am and closes at 4:00pm but the display just shows the green 'Open' all of the time... Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 25, 2009 Share Posted March 25, 2009 If you're wanting to read the USER'S clock you'll need to use Javascript and not PHP. Quote Link to comment Share on other sites More sharing options...
Silverado_NL Posted March 25, 2009 Share Posted March 25, 2009 Hey. I do not think the users personal time will be good for this. as it will affect the script when the clock is set wrong, or when the user is in another time zone. for example: if the users clock is 5 minutes behind and they look on the website, they will see the stock market is still open, while it is not and has not been for the last 5 minutes.(same goes if u are in another timezone) why not use unix timestamp and let all the date/time checking be done server sided. u can make new timestamps on each page request(timestamp of current time), and compare them to the opening/closing timestamps of that day. if current time if higher then the opening time AND lower then closing time, display open, else display closed. <?php // $open //should have a timestamp holding opening time of today // $close //should have a timestamp holding closing time of today $current_time = time(); // this holds the current time if($current_time > $open AND $current < $close){ $stat = '<b><font color="green">Open</font></b>'; }else{ $stat = '<b><font color="red">Closed</font></b>'; } ?> there might be more efficient ways to do this, but this is the way i would do it. quicker, probely easyer, and no need to use anything other then php, plus its precise to the second. hope this helps u. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.