liomon41 Posted June 13, 2012 Share Posted June 13, 2012 The code below allows users to access a particular page 1 hour prior to a given time and date else the link the page would be disabled. Thanks to some you guys on this forum i was able to achieve this.. But i kinda forgot mention that the time been retrieve from the db has to in GMT... The idea is whatever timezone you are right now, you comparing your current to the GMT($time) in the db... and ideas??? ...//// code.... <?php //Function to create a link or not based upon 'active' status function forecastLink($text, $url, $id, $clickable) { if(!$clickable) { return $text; } return "<a href='{$url}' id='{$id}'>{$text}</a>"; } //Create var to hold output $output = ''; //Create/run query for all records ordered by date $query = "SELECT firstTeam, secondTeam, gameId, date, time, IF(SUBTIME(TIMESTAMP(`date`, `time`), '1:0:0') > NOW(), 1, 0) as active FROM fixtures ORDER BY date, time"; $result = mysql_query($query); //Create flag variable to keep track of date $currentDate = false; while($row = mysql_fetch_array($result)) { //Convert date to common format $displayDate = date("D, M j, Y", strtotime($row['date'])); //Check if this is a new date if($currentDate != $displayDate) { //Display date header $currentDate = $displayDate; $output .= "<tr><td colspan='8' align='left' class='td'><b>{$currentDate}</b></td></tr>"; } //Extract and process the data for display $first = htmlspecialchars($row['firstTeam']); $second = htmlspecialchars($row['secondTeam']); $gameid = $row['gameId']; $linkActive = $row['active']; $real_time = date("H:i", strtotime($row['time'])); //Display record $url = "forecast.php?first1={$first}&second1={$second}&game_id={$gameid}"; $output .= "<tr class='big'>\n"; $output .= "<td width='56' align='left' style='color:#709b52;'><a href='' class='result_hover'>results</a></td>\n"; $output .= "<td width='182' align='right'>" . forecastLink($first, $url, 'fixtures_f', $linkActive) . "</td>\n"; $output .= "<td width='-31' align='center'>" . forecastLink('vs', $url, 'fixtures_v', $linkActive) . "</td>\n"; $output .= "<td width='-12' align='left'>" . forecastLink($second, $url, 'fixtures_s', $linkActive) . "</td>\n"; $output .= "<td>" . forecastLink($real_time, $url, 'fixtures_t', $linkActive) . "</td>\n"; $output .= "</tr>\n"; } ?> <table width="525" border="1" cellpadding="40" height="63" > <?php echo $output; ?> </table> Quote Link to comment https://forums.phpfreaks.com/topic/264130-changing-time-to-gmt-using-php/ Share on other sites More sharing options...
Pikachu2000 Posted June 13, 2012 Share Posted June 13, 2012 When posting code, enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/264130-changing-time-to-gmt-using-php/#findComment-1353590 Share on other sites More sharing options...
chrispulliam Posted June 13, 2012 Share Posted June 13, 2012 You can change the time zone a number of ways. To do it via your PHP script follow this link: http://support.modwest.com/content/5/258/en/how-do-i-change-timezone-for-php.html and you can do it within your PHP ini file follow directions here: http://wordpress.org/support/topic/php-530-amp-wp-28-it-is-not-safe-to-rely-on-the-systems-timezone I hope this helps accomplish what your needing! Quote Link to comment https://forums.phpfreaks.com/topic/264130-changing-time-to-gmt-using-php/#findComment-1353608 Share on other sites More sharing options...
lnemo Posted June 13, 2012 Share Posted June 13, 2012 If I understand correctly, this is what you're looking for: http://php.net/manual/en/function.gmdate.php //... $gmtDateStr = gmdate("D, M j, Y", strtotime($row['date'])); // $gmtDateStr is now formatted in GMT time //... Quote Link to comment https://forums.phpfreaks.com/topic/264130-changing-time-to-gmt-using-php/#findComment-1353614 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.