how to parse data between two date ranges

  • Thread starter perl_help_needed
  • Start date
P

perl_help_needed

Hi All,

I need to parse some data between two date ranges. These date ranges
are dynamic and need to be given by the user at CLI. The date format is
YY/MM/DD. I have written a perl script where i use static date, by
hardcoding it into the code. But i now need to have dynamic
functionality.

Could someone guide me thorugh this problem.
Thanks in advance.
 
I

it_says_BALLS_on_your forehead

perl_help_needed said:
Hi All,

I need to parse some data between two date ranges. These date ranges
are dynamic and need to be given by the user at CLI. The date format is
YY/MM/DD. I have written a perl script where i use static date, by
hardcoding it into the code. But i now need to have dynamic
functionality.

Could someone guide me thorugh this problem.
Thanks in advance.

what's CLI?
 
I

it_says_BALLS_on_your forehead

perl_help_needed said:
Hi All,

I need to parse some data between two date ranges. These date ranges
are dynamic and need to be given by the user at CLI. The date format is
YY/MM/DD. I have written a perl script where i use static date, by
hardcoding it into the code. But i now need to have dynamic
functionality.

Could someone guide me thorugh this problem.
Thanks in advance.

oh, maybe command line interface? in the beginning of your program you
can either do some shifts, or look at the contents of @ARGV.
 
P

perl_help_needed

what i actually need is the method to allow the usage of variying dates
in my script. Ex: i might want to find some data b/w 05/08/01 and
05/08/07 (yy/mm/dd). I can not hardcode these dates in my program. So
need to find a algorithm to specify the date range in perl program.
 
I

it_says_BALLS_on_your forehead

perl_help_needed said:
Hi All,

I need to parse some data between two date ranges. These date ranges
are dynamic and need to be given by the user at CLI. The date format is
YY/MM/DD. I have written a perl script where i use static date, by
hardcoding it into the code. But i now need to have dynamic
functionality.

Could someone guide me thorugh this problem.
Thanks in advance.

oh, maybe command line interface? in the beginning of your program you
can either do some shifts, or look at the contents of @ARGV.
 
J

Jon

perl_help_needed said:
what i actually need is the method to allow the usage of variying dates
in my script. Ex: i might want to find some data b/w 05/08/01 and
05/08/07 (yy/mm/dd). I can not hardcode these dates in my program. So
need to find a algorithm to specify the date range in perl program.

You could try converting the dates into timestamps then do something like this
to check whether its in range.

<psuedo_code>
if ($data_date < $end_date and $data_date > $start_date)
{
do stuff
}
</psuedo_code>

Have a look at Date::parse or Date::Calc for converting Date strings into Unix
timestamps.

HTH
 
X

xhoster

perl_help_needed said:
Hi All,

I need to parse some data between two date ranges.

I assume you meant "between two dates", or "within one date range".
Being between two date ranges would be a pretty weird thing to check.

How are you supposed to know whether it is between the two dates
until *after* you parse it? You need to first parse it, and then
figure out if it is within the date range.
These date ranges
are dynamic and need to be given by the user at CLI. The date format is
YY/MM/DD. I have written a perl script where i use static date, by
hardcoding it into the code. But i now need to have dynamic
functionality.

Could someone guide me thorugh this problem.
Thanks in advance.

It seems pretty obvious to me. Since I have no idea how you are screwing
it up, I have no idea how to guide you through it. Show us the (relevant)
code!

Xho
 
S

sopan.shewale

Hi,

Just try following script----Note : The date format is MM/DD/YY -

#!/usr/bin/perl

use strict;
use warnings;
use Date::Manip;

#### Date format should be : MM/DD/YY

my $date0 = shift;
my $date1 = shift;
my $base = $date1;

my $string = "0:0:0:1:0:0:0";

my @dates = map UnixDate($_, "%m\/%d\/%y"), ParseRecur($string, $base,
$date0, $date1);

print "The Dates Between $date0 and $date1 are : @dates\n";
 
D

Dave Weaver

my @dates = map UnixDate($_, "%m\/%d\/%y"), ParseRecur($string, $base,
$date0, $date1);
^ ^
Note that "/" isn't special in double-quoted string.
There is no need to escape it (which only leads to ugly looking
"leaning toothpick syndrome") :

my @dates = map UnixDate($_, "%m/%d/%y"), ...
 
W

William James

perl_help_needed said:
what i actually need is the method to allow the usage of variying dates
in my script. Ex: i might want to find some data b/w 05/08/01 and
05/08/07 (yy/mm/dd). I can not hardcode these dates in my program. So
need to find a algorithm to specify the date range in perl program.

#!ruby

class String
def to_time
Time.local( *(self.split('/')) )
end
end

print "First date (yy/mm/dd): "
first = STDIN.gets.chomp
t_first = first.to_time
print "Second date (yy/mm/dd): "
second = STDIN.gets.chomp
t_second = second.to_time

ARGF.each_line { |line|
if line =~ %r{\b(\d\d/\d\d/\d\d)\b}
if $1.to_time.between?( t_first, t_second )
print line
end
end
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top