Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^4: Timezone antidote

by hatter (Pilgrim)
on Sep 01, 2005 at 12:00 UTC ( [id://488356]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Timezone antidote
in thread Timezone antidote

GMT is the storage solution, not the output format. Store all the times in UTC/GMT, and when you actually need to print them out, then use TZ-aware tools and use the localtime features. From one of my scripts, I have:
use POSIX qw(LC_TIME); $ENV{'TZ'} = "GMT-1"; $locale = "gb_UK"; POSIX::setlocale(LC_TIME,$locale); my $todaysdate = POSIX::strftime("%a %b %d %H:%M",localtime());
For the machines in the UK, that changes between -1 and -0 for summer and not, and the machines in germany, that changes between -2 and -1 for summer and winter, and locale is de_DE. Calling localtime() will then view the time as it should be in your locale.


the hatter

Replies are listed 'Best First'.
Re^5: Timezone antidote
by Andre_br (Pilgrim) on Sep 06, 2005 at 17:11 UTC
    Hello hatter and everybody

    Thanks for the tips. Specially yours, hatter. But, tell me, any tip for mysql? My problem is the 'timestamp' fields, on wich rely my code and I´d have to convert them all to 'datetime' and make my code treat this offset.

    I tried setting the default of this 'timestamp' column to CURRENT_TIMESTAMP + interval 4 hour but this formula isn´t accepted by mysql as a default. I thought then about setting some kind of variable as now() + interval 4 hour but I think it won´t work either.

    Any ideas? My host said there´s no way to set a different time_zone through .my.cnf

    Thanks

    André

      DATE_ADD(NOW(),INTERVAL 4 hour) would be the option if you're setting itn in your INSERTs, DATE_ADD(CURRENT_TIMESTAMP, INTERVAL 4 hour) may work in the column definition as the default value, if you've not tried that already.


      the hatter

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://488356]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 15:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found