Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timezone change with Date::Manip

Status
Not open for further replies.

pflakes

Technical User
Jan 27, 2004
31
US
I'm writing a program which retrieves data from a 3rd party and inserts it into a sql database. The data provided has timestamps in GMT and I want to insert them with both the GMT time and Central time.

I've got everything working right now but when happens when daylight savings ends. Here's my current code.

use Date::Manip;

my $date = &ParseDate("$gmt_datetime");
$cst_datetime = &Date_ConvTZ($date,"GMT","CDT");

Do I have to change my code to use CST when daylight savings ends or if there someway to work around this.
 
I think BST is the problem, which you're not using (British Summer time)

AFAIK, GMT and UTC are the same

--Paul

I'm ready to learn if that ain't correct
 
The data I receive is in GMT -- I can't change that. I'm in Central time and need to convert to central time - which does observe daylight savings. How does BST affect what I'm doing.
 
British Summer Time is GMT+1 (or -1) AFAIK while its in effect. I work in Ireland, so it's never really been a problem for me.

How is the time being stored? 10:20, or as number of secs since epoch?

--Paul
 
The time is stored as '4/27/2004 17:32'. I've tried changing my code to change from BST to CDT and changing the date to '1/27/2004 17:32' -- when daylight savings isn't observed but that doesn't seem to work either.

The module doesn't seem look at the date to see if daylight savings is in effect. I may just have to put in some logic and look for the 1st Sunday in April and the last Sunday in October and then convert the time accordingly.
 
After a little more work I think I figured out what to do:

Using localtime, I can find whether daylight savings is active or not. Then create an if statement that converts either to CST or CDT.

my $sec;
my $min;
my $hour;
my $mday;
my $mon;
my $year;
my $wday;
my $yday;
my $isdst;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();


if ($isdst=0)
{
print("no\n");
$date = &Date_ConvTZ($date,"GMT","CST");
print $date;
}
else
{print("yes\n");
$date = &Date_ConvTZ($date,"GMT","CDT");
print $date;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top