Hi all,
I am total new to php and even coding, i am a netadmin.
Now my webmaster has quited, and we are in search of new webmaster, till the time been i am in charge of the site.
I need to add a time difference been the market open and market close (related to stock exchange)
so pls can u help me in coding this.
My market opens at 9:15 am and closes at 12:30.
I need to show the time difference between the current time to market open,
and also time left to market close after the market is open. i have done something is u can check if its correct or wrong.
<?php
function mktcls_diff($time1, $time2) {
$time_diff = strtotime($time2) - strtotime($time1);
$hours = floor($time_diff / 3600);
$minutes = floor(($time_diff % 3600) / 60);
// Just returning the string...
// can change this if you like so that
// it returns an array of the hours/minutes, etc...
return("$hours:$minutes");
}
function mktopn_diff($time1, $time3) {
$time_diff = strtotime($time3) - strtotime($time1);
$hours = floor($time_diff / 3600);
$minutes = floor(($time_diff % 3600) / 60);
// Just returning the string...
// can change this if you like so that
// it returns an array of the hours/minutes, etc...
return("$hours:$minutes");
}
// Test Call
$time1 = date ("h:i:s");
$time2 = "12:30:00";
$time3 = "09:15:00";
$diff = mktcls_diff($time1, $time2);
$diff2 = mktopn_diff($time1, $time3);
//print date ("H:i");
//print $diff;
//print $diff2;
echo "<B>OPEN<BR></B>";
//Market Open Check
if ($time_diff <= $time1) {
echo "Market Closed<br>";
}
else {
echo "Market Open";
echo $diff2 ("hours left for Market to Open.");
}
print $diff2+$hours;
//CLOSE
echo "<br><BR><B>CLOSE</B>";
//Market Close Check
if ($time_diff <= $time1) {
echo "<br>Market Closed<br>";
}
else {
echo "Market Open";
echo $diff("hours left for Market to Close.");
}
print $diff;
?>
this is my testing code that i am working on.
Thanks