Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^4: Timezone antidote

by hatter (Pilgrim)
on Sep 01, 2005 at 12:00 UTC ( #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

Comment on Re^4: Timezone antidote
Select or Download Code
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



      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?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2015-11-30 00:28 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (754 votes), past polls