Jump to content

Date timezone help


lukep11a

Recommended Posts

Hi, the date column of my login table is updated with the current time when a user registers, can anyone tell me how I can change the query below so that login.date is converted to GMT+0100?

 

<?php
        $query = "SELECT test_teams.team, test_teams.selectiongroup, SUM(test_team_points.points) AS total FROM test_teams, test_team_points, login, test_selections WHERE login.userid = '{$_SESSION['userid']}' AND login.userid = test_selections.userid AND test_selections.teamid = test_teams.teamid AND test_teams.teamid = test_team_points.teamid AND login.date < test_team_points.date GROUP BY test_teams.teamid ORDER BY test_teams.selectiongroup";
        $result = mysql_query($query) or die(mysql_error());
        
        while($row = mysql_fetch_assoc($result))
        {
        ?>

Link to comment
https://forums.phpfreaks.com/topic/244770-date-timezone-help/
Share on other sites

change your code to this.

 

<?php
date_default_timezone_set('Europe/London');

$query = "SELECT test_teams.team, test_teams.selectiongroup, SUM(test_team_points.points) AS total FROM test_teams, test_team_points, login, test_selections WHERE login.userid = '{$_SESSION['userid']}' AND login.userid = test_selections.userid AND test_selections.teamid = test_teams.teamid AND test_teams.teamid = test_team_points.teamid AND login.date < test_team_points.date GROUP BY test_teams.teamid ORDER BY test_teams.selectiongroup";
        $result = mysql_query($query) or die(mysql_error());
        
        while($row = mysql_fetch_assoc($result))
        {
        ?>

Link to comment
https://forums.phpfreaks.com/topic/244770-date-timezone-help/#findComment-1257268
Share on other sites

Redo what? That will convert any datetime from MySQLs default time zone to your destination time zone.

 

I have no idea what the rest of your script does, or what you're trying to accomplish. Your job as a programmer is to take that snippet and make it work for what you're trying to do.

Link to comment
https://forums.phpfreaks.com/topic/244770-date-timezone-help/#findComment-1257318
Share on other sites

Lukep11a, u are supposed to use that code and implement it in your mysql query thus u dont need to redo it. Its done automatically by the php page when the user register. If u dont understand how it works then just use date_default_timezone_set();

Link to comment
https://forums.phpfreaks.com/topic/244770-date-timezone-help/#findComment-1257403
Share on other sites

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.