Sponsored Content
Top Forums Shell Programming and Scripting Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl Post 302334827 by KevinADC on Thursday 16th of July 2009 03:12:31 PM
Old 07-16-2009
Quote:
Originally Posted by akil
Hi ,
This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated.

Code:
use Time::Local;

my $d = $ARGV[0];
my $t = $ARGV[1];
my $m = "";

@d = split /\//, $d;
@t = split /:/, $t;

if ( $d[0] eq "Jan" ) { $m = 0 }
elsif ( $d[0] eq "Feb" ) { $m = 1 }
elsif ( $d[0] eq "Mar" ) { $m = 2 }
elsif ( $d[0] eq "Apr" ) { $m = 3 }
elsif ( $d[0] eq "May" ) { $m = 4 }
elsif ( $d[0] eq "Jun" ) { $m = 5 }
elsif ( $d[0] eq "Jul" ) { $m = 6 }
elsif ( $d[0] eq "Aug" ) { $m = 7 }
elsif ( $d[0] eq "Sep" ) { $m = 8 }
elsif ( $d[0] eq "Oct" ) { $m = 9 }
elsif ( $d[0] eq "Nov" ) { $m = 10 }
elsif ( $d[0] eq "Dec" ) { $m = 11 };

$time = timelocal($t[2], $t[1], $t[0], $d[1], $m, $d[2]);

print "$time\n";usage :

Thank,
Akil
Are you passing one or two arguments to the script? You only mention YYYYMMDD but your code appears to be expecting two arguments:

Code:
my $d = $ARGV[0];
my $t = $ARGV[1];


Assuming two arguments, see if this helps:

Code:
use Time::Local;

my $d = $ARGV[0];
my $t = $ARGV[1];
my ($y, $m, $d) = unpack("A4A2A2",$d)
my ($h, $min, $s) = split(/:/,$t);
$time = timelocal($s, $min, $h, $d, $m-1, $y);

print "$time\n";usage :

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing variable to perl

I need a non-perl (bash) way to strip the path from a list of "find" results. Below is the perl version which I could use, if I could figure out how to call the script with a variable (like in sh, $1 is the variable passed in ./script variable) $file = "/path/to/file.txt"; # How do I... (2 Replies)
Discussion started by: TheCrunge
2 Replies

2. Shell Programming and Scripting

Passing Value from Shell to Perl

Hi All, I am calling a perl program in my shell script as follows. MY_IN_FILE=ABC.dat MY_OUT_FILE=XYZ.dat MY_VARIABLE="SomeValue" perl mycode.pl $MY_IN_FILE > $MY_OUT_FILE Question:- Now I want to pass value of $MY_VARIABLE from script to perl... How do I do that? Can someone... (5 Replies)
Discussion started by: hcbhatt
5 Replies

3. Shell Programming and Scripting

PERL String to Date (Custom format yyyymmdd to dd-mon-yyyy)

Hi All, I am learning PERL for one of the projects, and in one of these scripts, I read a flat text file and print in the terminal. The problem is, the text file has a date field. The format is yyyymmdd. I need to display this as dd-mon-yyyy. Any ideas to do this? Thanks a lot for the... (9 Replies)
Discussion started by: guruparan18
9 Replies

4. Shell Programming and Scripting

Date after 5 days from current date in YYYYMMDD format

Hello Experts, How do i get date after 5 days from current date in YYYYMMDD format? How do you compare date in YYYYMMDD format? Thanks (8 Replies)
Discussion started by: needyourhelp10
8 Replies

5. Shell Programming and Scripting

Validating date in yyyymmdd format using PERL

Hi all, i had a code where in user will enter a date in yyyymmdd format.. i didnt use any validation for the date and now the problem is if a user enters date instead of month after year it is proceeding with the code.. like if the date is 20120426 and if the user enters 20122604 it... (4 Replies)
Discussion started by: smarty86
4 Replies

6. Shell Programming and Scripting

Perl :Is it possible to read the excel 2007 sheet on unix machine using spredsheet::xlsx module

I have an Excel 2007 excel sheet on windows machine and using Spreadsheet::XLSX I had written a script to read the excel sheet and was successful. My requirement is I need to generate another excel sheet from the old excel 2007 sheet on unix machine. Now is it possible to read the excel... (2 Replies)
Discussion started by: giridhar276
2 Replies

7. Shell Programming and Scripting

Problem in passing date to external function from perl script.

my $sysdate = strftime('%Y-%m-%d', localtime ); biDeriveByDate('Table_Str',$sysdate,\@lIndx,\@lResVals) In a perl script, when I'm trying to pass $sysdate to some external function it's not working since $sysdate is passed as a string mentioned above but my function is expecting a date value... (1 Reply)
Discussion started by: Devesh5683
1 Replies

8. Shell Programming and Scripting

Perl:: mass replacement of converting C code formats to tgmath.h

hello, i have a lot of C old code I'm updating to C11 with tgmath.h for generic math. the old code has very specific types, real and complex, like cabsl, csinhl, etc usually for simple bulk replacements i would do something simple like this perl -pi -e 's/cosl/cos/g' *.c the reference... (0 Replies)
Discussion started by: f77hack
0 Replies

9. Programming

Date format change from mm/dd/yyyy to yyyymmdd in comma seperate line in perl

Hi All, I have line ,A,FDRM0002,12/21/2017,,0.961751583,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, it contains date in mm/dd/yyyy format i want to change this to yyyymmdd format using perl. Use code tags, thanks. (8 Replies)
Discussion started by: vishal0746
8 Replies

10. Shell Programming and Scripting

Perl to parse a variety of formats

The below perl script parses a variety of formats. If I use the numeric text file as input the script works correctly. However using the alpha text file as input there is a black output file. The portion in bold splits the field to parse f or NC_000023.10:g.153297761C>A into a variable $common but... (3 Replies)
Discussion started by: cmccabe
3 Replies
IDATE(1)							   User Commands							  IDATE(1)

NAME
ical - A Hijri/Islamic calendar (and converter) SYNOPSIS
ical [--gregorian yyyymmdd] [--hijri yyyymmdd] [--umm_alqura] [--fixed_view] [--dual] [--help] DESCRIPTION
The ical program is a Hijri/Islamic calendar displayer. It utilizes and includes a Gregorian to Hijri (and vice-versa) date converter. The application uses and offers multiple calculation methods with not all of them agreeing at all times. The reason for this multiplicity is due to not having one agreed upon method and so various entities develop and advocate their calculations. ical is able to comprehend and calculate both pre-epoch or pre-Hijrah, denoted as "B.H", as well as post-epoch or post-Hijrah, denoted as "A.H", dates. ical also utilizes Gregorian's pre-epoch "B.C" and post-epoch "A.D" dates and notes them per its output. When entering pre- epoch years, negative numbers ought to be utilized. ical when run without any command-line options uses the host machine's Gregorian date and converts it to Hijri to display that month's view. Entries enclosed by [] denote exact day specified. OPTIONS
ical follows the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of all options is noted below: -h, --help Show summary of options -g, --gregorian yyyymmdd Specify the Gregorian date to be converted where 'y' stands for year, 'm' for month and 'd' for day -hi, --hijri yyyymmdd Specify the Hijri date to be converted where 'y' stands for year, 'm' for month and 'd' for day -u, --umm_alqura Specify to use the Umm Al-Qura calculation method (used mostly in Saudi Arabia) -f, --fixed_view Show a fixed week view (ie. start on Sun and end on Sat) else default to showing the preferred week view of the resulting calendar (Gregorian starts on Sunday, Hijri starts on Saturday) -d, --dual Show both converstion from and to calendar months simultaneously BACKGROUND
The Hijri calendar is used in most of the Arab world and is the symbolic calendar of the Islamic faithed worldwide. This calendar is known as the "Hijri" (based on the word "Hijrah" - denoting migration in Arabic) to signal Prophet Mohammed's (PBUH) migration from Makkah to Medinah on Thursday, July 15, 622 AD (Julian). The Islamic Hijri calendar is strictly lunar (ie. moon-based) with twelve lunar months which do not correspond or track their solar coun- terparts (the Gregorian calendar is a solar or sun-based calendar). Lunar years and thus Hijri years are, on average, about 354 days long resulting in a Hijri year being roughly about 11 days shorter than its Gregorian counterpart. There is much discussion and confusion regarding how best to track the Hijri calendar. A great deal of that confusion is based on the fact that many relay on a human moon sighting to denote the start (or end) of a month (each month of the Hijri calendar starts when a new moon's crescent is observed or is made visible at sunset) as opposed to using an empirical mathematic certainty. The methods presented in this application and its underlying ITL library are strictly arithmetic in nature and do NOT take moon-phases into consideration (in short, observational approximation is not used). LIMITATIONS
There is currently no Umm Al-Qura support. REPORTING BUGS
Report bugs on the web using http://bugs.arabeyes.org AUTHOR
Written by Nadim Shaikli as part of the Arabeyes.org project. COPYRIGHT
ical is subject to the GNU General Public License (GPL). Copyright (C) 2005, Arabeyes, Nadim Shaikli. SEE ALSO
The ITL (Islamic Tools Library). It is the underlying requirement for ical to function. The ITL library was created and is hosted at www.arabeyes.org. ical January 05, 2005 IDATE(1)
All times are GMT -4. The time now is 05:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy