Jump to content

[SOLVED] MySql Query Change Timezone


hoopplaya4

Recommended Posts

Hi All,

 

This is probably an easy question.  I have a timestamp in my mysql database that I'd like to display in Pacific (Los Angeles) time.  The mysql time appears to be set at GMT.  How would I go about displaying the timestamp in Pacific time?

 

Here's my current query right now:

 

<? 
require("../connection.php");
$rs = mysql_db_query($DBname,$sql,$link);

$data = mysql_query("SELECT * FROM tblAnnouncements ORDER BY announceID DESC LIMIT 5") or die(mysql_error());


while($info = mysql_fetch_array( $data ))
{
print ("<li>");
print ("<p>" . $info['announcement'] . "  ");
print ("<br><small>Posted by Johnny on ");
print("" . date("g:i a F j, Y ", strtotime($info["announceCreate"])) . "</small></p>");
print ("</li>");
}
?>

 

Any help is appreciated!

Link to comment
Share on other sites

Thanks for the reply Mchl.

 

using "date_default_timezone_set('America/Los_Angeles');" works in an instance where I will display the current time.  For example, "echo date("g:i a")"

 

However, the mysql values remain unchanged.  Is there anything else I'd need to add to my statement?

Link to comment
Share on other sites

Hmm, that seemed to totally throw the hours, minutes, and even the dates.  This is what I'm getting back now.  (I even tried to use your example of +2 hours).

 

2:29 pm September 24, 1911
2:24 pm September 24, 1911
1:37 pm September 24, 1911
2:03 pm September 23, 1911
1:45 pm September 23, 1911

 

When it used to be:

 

10:55 am November 30, 2008
10:50 am November 30, 2008
10:03 am November 30, 2008
10:29 am November 29, 2008
10:11 am November 29, 2008 

 

 

Link to comment
Share on other sites

Thanks for the reply.  The updated PHP code did it for me.

 

date("g:i a F j, Y ", strtotime($info["announceCreate"] .'+2 hours'))

 

Also, thanks for the tip on the SELECT statement.  Unfortunately, I'm using MySql 4.12, and apparently "convert_tz" only works with 4.13+.  So, I'll have to go with the PHP update for now.

 

Thanks again!

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.