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
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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.