Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Date::Manip - date differences - one hour

by denzil_cactus (Sexton)
on Oct 10, 2014 at 11:30 UTC ( [id://1103398]=perlquestion: print w/replies, xml ) Need Help??

denzil_cactus has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks !! I am facing issue with Data::Manip::ParseDate function on perl 5.10.1 as its adding extra one hour.
#!/usr/bin/perl use Time::Local qw(timelocal timegm timegm_nocheck); use POSIX qw(strftime); use Date::Manip; &dateTimeFormat; sub dateTimeFormat { my($iSec,$iMin,$iHour,$iMday,$iMon,$iYear,$iWday,$iYday,$iIsds +t) = localtime(time); $iYear += 1900; $iMon++; my $tDate = sprintf('%04d-%02d-%02d',$iYear,$iMon,$iMday); my $tTime = sprintf('%02d:%02d:%02d',$iHour,$iMin,$iSec); my $cZone = strftime("%Z", localtime()); my $cString = $tDate.$tTime.$cZone; my $cParsedate = ParseDate($cString); my $tNewdate = UnixDate($cParsedate, "%Y-%f-%d"); my $tNewtime = UnixDate($cParsedate, "%H:%M:%S"); my($tYear,$tMonth,$tDd) = split(/-/,$tNewdate); $tNewdate = sprintf('%04d-%02d-%02d',$tYear,$tMonth,$tDd); my($HH,$MM,$SS) = split(/:/,$tNewtime); $tNewtime = sprintf('%02d:%02d:%02d',$HH,$MM,$SS); my $cDatetime = $tNewdate." ".$tNewtime; print $cDatetime; }
Below is the output of the program
[denzil@local ~]# perl 1.pl 2014-10-10 12:16:12 [denzil@local ~]# date Fri Oct 10 11:16:13 GMT 2014 [root@cjjeiprodb ~]#
Can you please help me to fix this?

Replies are listed 'Best First'.
Re: Date::Manip - date differences - one hour
by rnewsham (Curate) on Oct 10, 2014 at 11:56 UTC

    It looks like its a timezone or daylight savings issue, on my system it works as expected. It might help if you examine the contents of $cZone.

      It's definitely a daylight saving time issue. If you read the Date::Manip::Problems document, it's one of the problems mentioned.

      Also, if you run Date::Manip 6.30 or newer, it'll generally show you the answer you 'expect'.

Re: Date::Manip - date differences - one hour
by ikegami (Patriarch) on Oct 10, 2014 at 15:13 UTC

    What are you trying to do?! It's a minor miracle that ParseDate can handle something like 2014-10-1008:11:02PDT at all!

    You should have better luck using %z than semi-meaningless %Z. Do you also have the problem with %z? Maybe you have a misconfigured system. Today, perl -MPOSIX -E'say strftime("%z", localtime)' should return +0200 for Swedes.

      Thanks for your input guys!!

      I just set this export TZ=GMT and it worked

      Got the help from http://www.perlmonks.org/bare/?node_id=289914
      If you are your application from cron then TZ=GMT needs to be set in the cron daemon.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-25 09:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found