Link to home
Start Free TrialLog in
Avatar of Norman Manzo Nora
Norman Manzo Nora

asked on

How to convert DATE/TIME String values from GMT to GMT+8, and then Calculate the difference in seconds using BASH or PERL script

Hi experts,

Need help on how to convert a string of values in both 2nd and 3rd fields that are actually Date and Time in GMT and then calculate the difference in seconds.
Preferably using the following scripting methods:  BASH or PERL

Sample source file in CSV:  inputfile.csv

Label,StartDateTime,EndDateTime,status
info01,20171231155000,20171231161000,complete
info02,20180101023025,20180101024045,complete
info03,20180430222210,20180430223002,complete
info04,20180612113050,20180612113502,complete

Open in new window




===============================================================================================

Required Output File: Start and End Date/Time in GMT+8, plus the Date/Time difference or Duration (in seconds) inserted as a new column (4th field)

Output CSV File:  outputfile.csv

Label,StartDateTime,EndDateTime,Duration(Seconds),status
info01,20171231235000,20180101001000,1200,complete
info02,20180101103025,20180101104045,620,complete
info03,20180501062210,20180501063002,472,complete
info04,20180612193050,20180612193502,252,complete

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norman Manzo Nora
Norman Manzo Nora

ASKER

Thanks Wilcoxon.  This is what I need.  The script works.  

Although the output is ok, not sure why Perl is returning some message that seems to be errors.  I can choose to ignore this, but just wondering if you have an idea how to clear this?  

Once again, thanks for the help :-)



scripts$ ./test01.pl inputfile.csv 

Use of uninitialized value $arg in pattern match (m//) at ./test01.pl line 10, <$_[...]> line 6.
Validation failed for type named DayOfMonth declared in package DateTime::Types (/home/nmnora/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/DateTime/Types.pm) at line 29 in sub named (eval) with value undef

Trace begun at Specio::Exception->new line 57
Specio::Exception::throw('Specio::Exception', 'message', 'Validation failed for type named DayOfMonth declared in package DateTime::Types (/home/nmnora/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/DateTime/Types.pm) at line 29 in sub named (eval) with value undef', 'type', 'Specio::Constraint::Simple=HASH(0x1bb3a00)', 'value', undef) called at (eval 221) line 91
DateTime::_check_new_params('year', undef, 'month', undef, 'day', undef, 'hour', undef, 'minute', undef, 'second', undef, 'time_zone', 'UTC') called at /home/nmnora/perl5/lib/perl5/x86_64-linux-gnu-thread-multi/DateTime.pm line 176
DateTime::new('DateTime', 'year', undef, 'month', undef, 'day', undef, 'hour', undef, 'minute', undef, 'second', undef, 'time_zone', 'UTC') called at test01.pl line 11
main::ParseDate(undef) called at test01.pl line 22

Open in new window

Basically, the script works nicely.  Just encountered what seemed to be errors, but nevertheless, the desired output was achieved.
All of the errors except possibly the very first one appear to be coming from within DateTime.  I do not get those errors.  Which version of Perl and of DateTime are you using?