days difference perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting days difference perl
# 1  
Old 09-21-2012
days difference perl

Hi I have the following issue.

the headeer in the file contains as follows

Code:
 
IMAHDR tsmdsl01 EMBS_DAT 20120911 20120911
233656S000000000000000 001

So the fifth field in the header is a string that represents the file arrival date.(20120911) yyyyMMDD

I just need to compare it with current system date (using the date function)and get the days difference.

could you please help how can i do it simply in perl.

I have palyed around with date but not able to figure out.
# 2  
Old 09-21-2012
Code:
#!/usr/bin/perl

use strict;

use Date::Calc qw(:all);

while (<DATA>) {
chomp;
last unless $. == 1;
my @flds=split;
my ($year,$month,$day, $hour,$min,$sec) = Today_and_Now();

my $year1=substr($flds[4],0,4);
my $month1=int(substr($flds[4],4,2));
my $day1=int(substr($flds[4],-2));

print "Difference is - ", Delta_Days($year1,$month1,$day1,$year,$month,$day),"\n";

}

__DATA__
IMAHDR tsmdsl01 EMBS_DAT 20120911 20120911
233656S000000000000000 001

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Date difference using perl

Hi All, I am using the below code to get the days difference between 2 dates ddate="05/31/2018" bdate="06/10/2018" diff=$(perl -e 'use Time::Local; my ($month1,$day1,$year1)=split /\W+/, $ENV{'ddate'}; my ($month2,$day2,$year2)=split /\W+/, $ENV{'bdate'}; my $time1 =... (5 Replies)
Discussion started by: jayadanabalan
5 Replies

2. Shell Programming and Scripting

Need difference between days

Hi, I am not comfortable with dates and I fail to crack this. I have two strings Date1="Apr 22 23:59:59 2016 GMT" Date2="Dec 1 15:08:40 UTC 2015" I need to find the difference in days between the two dates which in this example is approx 140 days. Is there an easy way to get the... (3 Replies)
Discussion started by: mohtashims
3 Replies

3. Shell Programming and Scripting

Trouble calculating difference in number of days

Hi all, I have a requirement to calculate the difference of number of days of time stamp of a file and system date and if the difference is greater than 15 days it should prompt as previous month file otherwise current month file. Below is the code i used and it is working fine till now. (You... (2 Replies)
Discussion started by: Ravindra Swan
2 Replies

4. Shell Programming and Scripting

Difference in dates in days (ksh shell)

Hi Guys, Need a small help, how do i get the difference between two dates (in days) in KSH shell My date is in mm/dd/YYYY format, Is there a function to get time stamp from the respective date and time ( mm/dd/yyyy HH:MM:SS) (1 Reply)
Discussion started by: selvankj
1 Replies

5. Shell Programming and Scripting

Please help me days to a date string in PERL

Please help me n days to a date string in PERL. Date is of the format YYYYMMDD ---------- Post updated at 08:56 AM ---------- Previous update was at 08:54 AM ---------- Add n days (2 Replies)
Discussion started by: yahoo
2 Replies

6. Shell Programming and Scripting

Look back file days in PERL

I have 3 variables , $file =abc_2011_11_01.txt (current day file), $back = Yes and $forward = No I need to search for 3 days back files / 3 days forward files if my current file is not present logic is, I need to download the current day file. If it is missing, i need to look out for currentday... (4 Replies)
Discussion started by: irudayaraj
4 Replies

7. Shell Programming and Scripting

Perl Time Difference

I having probelm in time difference output using Delta_YMDHMS, using below start date and enddate I get -30days. Any idea how to fix this issue. output : 0,1,-30, 0,0,0 Thanks, Bataf use POSIX qw/strftime/; use Date::Calc qw(Delta_YMDHMS); use Time::Local; $start_date =... (1 Reply)
Discussion started by: bataf
1 Replies

8. Shell Programming and Scripting

Date Difference in PERL

Hi I have a file which has start time as my first line and End time in last line start time: 23 May 2008 03:30:33 End time : 23 May 2008 04:30:00 I have to extract these two lines and find the time of execution for the script in PERl. Any help appreciated Thanks (1 Reply)
Discussion started by: usshell
1 Replies

9. Shell Programming and Scripting

Days difference between two dates

Hello, I would like to find out the number of days between two dates of the format yyyy-mm-dd. Any help on this is highly appreciated. Thanks. (6 Replies)
Discussion started by: Data469
6 Replies

10. Shell Programming and Scripting

Difference between two dates in no of days ???

Hi All How to get the difference between two dates in no of days ??? My date format is like this YYYY/MM/DD. I have to get the no of days between two dates in the given format. I tried to search the forum but nothing came up similar to my requitement. Your help will be appreciated. ... (1 Reply)
Discussion started by: csaha
1 Replies
Login or Register to Ask a Question