GlowHost Web Hosting Forums  

Go Back   GlowHost Web Hosting Forums > In The Lounge > Programming Talk
Register Forum FAQ Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-05-2008
Scott's Avatar
Practically a Glow Sage
 
Join Date: Oct 2006
Posts: 24
Rep Power: 0
Scott is on a distinguished road
Default default timezone

what is the best way to set the default timezone for php scripts?

I have attempted:
PHP Code:
ini_set("date.timezone","America/Chicago"); 
but that doesn't seem to do the trick.

Any suggestions would be greatly appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-05-2008
Dmitriy's Avatar
Moderator
 
Join Date: Feb 2007
Location: Ukraine
Posts: 25
Rep Power: 0
Dmitriy is on a distinguished road
Default

Hey, Scott

What PHP version we're talking about? I presume PHP5...

You can try also using
bool date_default_timezone_set ( string $timezone_identifier )

Timezones list: PHP: List of timezones in the group America - Manual
Documentation on your issue: PHP: date_default_timezone_set - Manual

However, I'd suggest saving all date\time value in UTC & than add timezone offset before the output. This is better than to write to users from Japan that all times are UTC -6 or something like that.

Let me know how it goes
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-12-2008
Scott's Avatar
Practically a Glow Sage
 
Join Date: Oct 2006
Posts: 24
Rep Power: 0
Scott is on a distinguished road
Default

Alright, I got the php part to work but I am now having trouble with MySQL now().

Here is the code that I have so far:

PHP Code:
echo "<p>PHP 1: ".date("Y-m-d h:i:s")."</p>"// outputs system time, ok

$q "select now()";
$r mysql_query($q);
$d mysql_fetch_assoc($r);
echo 
"<p>MySQL 1: ".$d['now()']."</p>"// outputs system time, ok

putenv("TZ=America/Chicago"); // change php timezone
echo "<p>PHP 2: ".date("Y-m-d h:i:s")."</p>"// outputs my timezone, ok

$q "select now()";
$r mysql_query($q);
$d mysql_fetch_assoc($r);
echo 
"<p>MySQL 2: ".$d['now()']."</p>"// outputs system time, didn't expect this to work for my timezone but why not try

$q "set time_zone = '-5:00'"// change mysql timezone
$r mysql_query($q);

$q "select now()";
$r mysql_query($q);
$d mysql_fetch_assoc($r);
echo 
"<p>MySQL 3: ".$d['now()']."</p>"// outputs my timezone, ok 
Per the MySQL docs, I should be able to tell MySQL the timezone that I am in by name, so instead of writing:
PHP Code:
$q "set time_zone = '-5:00'"
I should be able to write:

PHP Code:
$q "set time_zone = 'America/Chicago'"
or:

PHP Code:
$q "set time_zone = 'US/Central'"
However, both of those attempts when using names fail and MySQL complains about them.

Per MySQL doc:
Named time zones can be used only if the time zone information tables in the mysql database have been created and populated.

Can we get these tables loaded or is there another solution to get now() to work as expected?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-13-2008
Scott's Avatar
Practically a Glow Sage
 
Join Date: Oct 2006
Posts: 24
Rep Power: 0
Scott is on a distinguished road
Default

No takers?
Am I the only one with this issue?
What are others doing to work around this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-13-2008
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default

I just use #'s. I only have to report one or two timezones, so I have no need for this sort of complication, so Im not a taker, sorry.

Here are the tables.
MySQL :: Time zone description tables

You can open a supprt ticket and give that link then make a request to have it installed in the mysql DB.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 03-13-2008
Scott's Avatar
Practically a Glow Sage
 
Join Date: Oct 2006
Posts: 24
Rep Power: 0
Scott is on a distinguished road
Default

So you do this ...

"set time_zone = '-5:00'"

How do you handle daylight savings time?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 03-13-2008
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default

I don't. Which is probably why one of my programmers had issues this weekend. I have always used PHP for the time, and it wasn't until this weekend that I got a sense of the ugliness of the fact that Mysql doesn't seem to get the time from the same place PHP does.
He handles my auction launcher for eBay, and many users had their scheduled auctions go out an hour late. Ughh....

I have been meaning to look further into this, and this may be the time.

But even if the tables get populated, I came accross indications that the tables would need to be constantly updated for that very reason. I didnt read hard enough or look at the structure to see how it handles that.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 03-13-2008
Scott's Avatar
Practically a Glow Sage
 
Join Date: Oct 2006
Posts: 24
Rep Power: 0
Scott is on a distinguished road
Default

We are in the same boat.

I was also looking for a way to set a domains timezone through CPanel because server logs are also annoying with the timestamps written to system time. Or possiblely through some Apache directive that could be added to htaccess file.

I am going to check further on the Apache thing and post back results.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 03-13-2008
Scott's Avatar
Practically a Glow Sage
 
Join Date: Oct 2006
Posts: 24
Rep Power: 0
Scott is on a distinguished road
Default

Well you can set your env variable using an Apache directive. Place this line in your .htaccess file in your document root directory:

SetEnv TZ America/Chicago

After placing this in my .htaccess file, PHP works like a champ and you no longer have to make the adjustment in your PHP code. However, MySQL still requires the per connection manipulation.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 03-13-2008
Matt's Avatar
chown -R us.us *YourBase*
 
Join Date: Jan 2005
Location: Moved to Florida!
Posts: 1,725
Rep Power: 10
Matt is a glorious beacon of lightMatt is a glorious beacon of lightMatt is a glorious beacon of lightMatt is a glorious beacon of lightMatt is a glorious beacon of lightMatt is a glorious beacon of light
Default

Quote:
Originally Posted by Scott View Post
How do you handle daylight savings time?
The scripts I have seen, have a checkbox which adjusts the script settings/clock by one hour when it is checked, or not checked respectively. But really, if PHP is using the server time then the time should always be right since that clock is updated by rdate.

As for MySQL, I have no idea, if anyone finds it, I'd be interested in it for a script I am working on as well.
__________________
:::::
01001100 00110011 00110011 00110111

Last edited by Matt; 03-13-2008 at 09:05 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 10:21 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO
Copyright 2000-2007 GlowHost.com