Jump to content

changing time to GMT using php


liomon41

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/264130-changing-time-to-gmt-using-php/
Share on other sites

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.