Basic perl code- Date format


 
Thread Tools Search this Thread
Top Forums Programming Basic perl code- Date format
# 1  
Old 07-07-2011
Basic perl code- Date format

Hi friends,

Please see the below code carefully.

=======================================================
Code:
# Get batch date and Ord range
open OR,$ARGV[2];
while (<OR>) { # find the batch date
next if length $_ < 3; # BLANK LINE
# last if $. > 120; # sample should be good enough
(undef,undef,undef,undef,$batch_date,$oId,undef)=split(/,/,$_,);
   $dates{$batch_date}++;

$firstOrder ||= $ordId;
}
close OR;
@maxdates = sort{$dates{$b} <=> $dates{$a}} keys %dates;
$batch_date = shift @maxdates;
undef @maxdates;


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

so whatever i am catching batch_date from $ARGV[2];

that is interms of date+time
eg:2011-05-20 07:38:28

i want that batch date should be only contain date 2011-05-20
I cant change the file so plz tell me how can i do this, so that in next step i can use maxdate (@maxdates = sort{$dates{$b} <=> $dates{$a}} keys %datesSmilie

so plz help me to do so

Regards,
priyanka

Last edited by pludi; 07-07-2011 at 10:13 AM..
# 2  
Old 07-07-2011
use the result of command ls -l in linux ,, use its 4rth entry to sort or copy whatever u want..

Moderator's Comments:
Mod Comment Removed email, as all Q&A should take place in the forums

Last edited by pludi; 07-07-2011 at 10:14 AM..
# 3  
Old 07-09-2011
Quote:
Originally Posted by pspriyanka
Hi friends,

Please see the below code carefully.

=======================================================
Code:
# Get batch date and Ord range
open OR,$ARGV[2];
while (<OR>) { # find the batch date
next if length $_ < 3; # BLANK LINE
# last if $. > 120; # sample should be good enough
(undef,undef,undef,undef,$batch_date,$oId,undef)=split(/,/,$_,);
   $dates{$batch_date}++;

$firstOrder ||= $ordId;
}
close OR;
@maxdates = sort{$dates{$b} <=> $dates{$a}} keys %dates;
$batch_date = shift @maxdates;
undef @maxdates;


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

so whatever i am catching batch_date from $ARGV[2];

that is interms of date+time
eg:2011-05-20 07:38:28

i want that batch date should be only contain date 2011-05-20
I cant change the file so plz tell me how can i do this, so that in next step i can use maxdate (@maxdates = sort{$dates{$b} <=> $dates{$a}} keys %datesSmilie

so plz help me to do so

Regards,
priyanka
Your problem boils down to converting a string like this -

Code:
2011-05-20 07:38:28

to this -

Code:
2011-05-20

After you capture the value of $batch_date and before you add it as a hash key, you may want to perform a trimming operation like the following -

Code:
$
$ perl -le '$batch_date = "2011-05-20 07:38:28"; $batch_date =~ s/ .*$//; print $batch_date'
2011-05-20
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

PERL : hhmiss - Date format check and replace

I have a filename, This can be any of any format, I want to check if the filename has hours,mins and seconds part. If it is present, i want to replace it with a " * " (star symbol) output needed: IMP: The time part can be in any pattern. How can this be done?:confused:... (3 Replies)
Discussion started by: irudayaraj
3 Replies

3. Shell Programming and Scripting

Different types of Date format in perl

I want to know the different types of date format possible in perl. Eg: yyyymmdd, yymmdd etc...Is there any format like YMD? Where can i find the list of all possibilites? Thanks in advance (1 Reply)
Discussion started by: irudayaraj
1 Replies

4. Shell Programming and Scripting

Perl basic code 3

Hi , I am having csv contains data 2011-08-23 11:11:00.074+0000: Info: Duplicate Order is not processed,Original Order Tuple ($category, $type) = split(',', $_ , 2); what is the split function work here?? Thanks Please start using code tags, thanks. (5 Replies)
Discussion started by: pspriyanka
5 Replies

5. Shell Programming and Scripting

perl basic code

Hi, foreach $cat (sort{$cats{$b} <=> $cats{$a}} keys %cats) can anyone explain me above code?? i am new to perl Thanks (1 Reply)
Discussion started by: pspriyanka
1 Replies

6. Shell Programming and Scripting

perl basic code

Hi, can anybody explain me below code $cats{$category}++ Thanks (2 Replies)
Discussion started by: pspriyanka
2 Replies

7. Programming

Basic perl code

hi, can anybody explain me the below code. i am new to perl ========================================== $o_dups{$1} = 1 if /^\w+\t.{19}\t(+),/; ========================================== regards, priyanka (2 Replies)
Discussion started by: pspriyanka
2 Replies

8. Shell Programming and Scripting

perl regular expression format date

Hi Everyone, Mon 18 Jan 2010 09:52:10 AM MYT the output is 20100118 09:52:10 how to do it in perl regular expression =~ Thanks (3 Replies)
Discussion started by: jimmy_y
3 Replies

9. UNIX for Dummies Questions & Answers

perl yesterday's date in mmddyyyy format

Hi, Below command is producing yesaterday's date in mmddyy format - perl -e '@T=localtime(time-86400);printf("%02d%02d%02d",$T+1,$T,($T+1900)%100)' But i want the date in mmddyyyy format; plz help. Thankx, Rahul Bahulekar. ---------- Post updated at 05:13 AM ---------- Previous... (1 Reply)
Discussion started by: rahulbahulekar
1 Replies

10. Shell Programming and Scripting

Date format in Perl

How do I display the date in the format "YYYY-Mmm-DD" using perl. e.g 2008-Jun-03 I have a perl command below which displays the date in the format "YYYY-MM-DD" but I want the month to be displayed as "Mmm" (The first 3 characters of the name of the month with the initial letter being upper... (2 Replies)
Discussion started by: stevefox
2 Replies
Login or Register to Ask a Question