Calculate time difference between pst and pdt dates in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Calculate time difference between pst and pdt dates in perl
# 1  
Old 03-19-2013
RedHat Calculate time difference between pst and pdt dates in perl

Hi,

how to calculate the time difference between PST date and PDT date in perl scripting.

date1: Mon Dec 31 16:00:01 PST 2015
date2: Tue Mar 19 06:09:30 PDT 2013

and also difference between PST-PST and PDT-PDT

need difference in months or days (months prefereble).
# 2  
Old 03-19-2013
Since you use a redhat icon it's probably a good guess you have linux, and therefore GNU date. Shell solution:

Code:
T1=$(date +%s -d "Mon Dec 31 16:00:01 PST 2015")
T2=$(date +%s -d "Tue Mar 19 06:09:30 PDT 2013")
DAYS=$(((T1-T2)/(60*60*24)))

Not sure how to do it in perl.
# 3  
Old 03-20-2013
Not tested but should be something like this:
Code:
#!/usr/bin/perl
 
use strict;
use Time::Piece;
use POSIX qw(strftime);
 
 
my $before = Time::Piece->strptime("Tue Mar 19 06:09:30 PDT 2013", "%a %b %d %H:%M:%S %Z %Y");
my $after  = Time::Piece->strptime("Mon Dec 31 16:00:01 PST 2015", "%a %b %d %H:%M:%S %Z %Y");


# Gap in seconds
my $secdiff = int ($after - $before);
 
 
# Format the result .
print  strftime( '%H:%M:%S', gmtime($secdiff))."\n";

# 4  
Old 03-20-2013
He almost certainly does not have Time::Piece...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calculate time difference between two lines

i grepped the time stamp in a file as given below now i need to calculate time difference file data: 18:29:10 22:15:50 (5 Replies)
Discussion started by: vivekn
5 Replies

2. Shell Programming and Scripting

Calculate time difference

I have time in a file in HH:MM:SS format as it contents(its not the file creation time). i need this to be converted to epoch time or time since 1970. The time is written into that file by a script, which i cannot modify. Im using AIX machine $ cat abc.txt 10:29:34 (2 Replies)
Discussion started by: gpk_newbie
2 Replies

3. Shell Programming and Scripting

Shell script to calculate difference between 2 dates

shell script to calculate difference between 2 dates (3 Replies)
Discussion started by: gredpurushottam
3 Replies

4. Shell Programming and Scripting

How to Calculate the difference between two dates?

I want the difference between two following date using scripts in terms of no.of days. How I can accomplish this. lastdate=Tue Nov 13 10:30:56 2012 currdate=Wed Dec 15 15:58:21 PAKST 2012 Ouput should be like this: Your Password will expire after = 32 Days on Wed Dec 15 15:58:21 PAKST... (1 Reply)
Discussion started by: m_raheelahmed
1 Replies

5. Shell Programming and Scripting

Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do... (10 Replies)
Discussion started by: worm
10 Replies

6. Shell Programming and Scripting

Calculate the Time stamp difference

hi, I have a log file which gives time stamps hh:mm:ss.sssss format in which hh- hours , mm -minutes ss.sssss - seconds.microseconds I need to calculate the time diff between sent time stamp and received time stamp .... could any one please help me.. i am tryin to write a script but... (2 Replies)
Discussion started by: firestar
2 Replies

7. Shell Programming and Scripting

How to calculate time difference between start and end time of a process!

Hello All, I have a problem calculating the time difference between start and end timings...! the timings are given by 24hr format.. Start Date : 08/05/10 12:55 End Date : 08/09/10 06:50 above values are in mm/dd/yy hh:mm format. Now the thing is, 7th(08/07/10) and... (16 Replies)
Discussion started by: smarty86
16 Replies

8. Shell Programming and Scripting

How to calculate the time difference.

Hi All, I've written a script which reads all the systems backup information and saves it in a log file. ssh -l ora${sid} ${primaryhost} "tail -1 /oracle/$ORACLE_SID/sapbackup/back$ORACLE_SID.log" | awk '{print $3,$4,$5,$6}' >> ${RESULTFILE} The output comes as below: 2008-09-30 06.00.01... (2 Replies)
Discussion started by: suri.tyson
2 Replies

9. Shell Programming and Scripting

How to calculate the time difference...

Hi All, I've written a script which reads all the systems backup information and saves it in a log file. ssh -l ora${sid} ${primaryhost} "tail -2 /oracle/$ORACLE_SID/sapbackup/back$ORACLE_SID.log" |head -1 | awk '{print echo "PREVIOUS:-- Start Date&Time: " $3,$4,echo "|| End Date&Time:... (1 Reply)
Discussion started by: suri.tyson
1 Replies

10. Shell Programming and Scripting

How to calculate this time difference

Hi, Please help me in calculating the time difference between below mentioned timestamps. a=07/17/2007 02:20:00 AM MST b=07/17/2007 02:07:46 AM MST Thanks (2 Replies)
Discussion started by: Prat007
2 Replies
Login or Register to Ask a Question