how to parse data between two date ranges

Discussion in 'Perl Misc' started by perl_help_needed, Aug 8, 2005.

  1. 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.
     
    perl_help_needed, Aug 8, 2005
    #1
    1. Advertising

  2. perl_help_needed wrote:
    > 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?
     
    it_says_BALLS_on_your forehead, Aug 8, 2005
    #2
    1. Advertising

  3. perl_help_needed wrote:
    > 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.
     
    it_says_BALLS_on_your forehead, Aug 8, 2005
    #3
  4. 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.
     
    perl_help_needed, Aug 8, 2005
    #4
  5. perl_help_needed wrote:
    > 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.
     
    it_says_BALLS_on_your forehead, Aug 8, 2005
    #5
  6. perl_help_needed

    Jon Guest

    perl_help_needed wrote:

    > 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
    --
    Jon
     
    Jon, Aug 8, 2005
    #6
  7. perl_help_needed

    Guest

    "perl_help_needed" <> wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Aug 8, 2005
    #7
  8. perl_help_needed

    Guest

    Hello,

    Just look at my blog http://sopanshewale.blogspot.com/ in Date::Manip
    difficulties, Q 2.

    You can use Date::Manip module to solve your problem.

    Regards,

    --sopan shewale
     
    , Aug 9, 2005
    #8
  9. perl_help_needed

    Guest

    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";



    ---

    Regards,
    --sopan shewale
     
    , Aug 9, 2005
    #9
  10. perl_help_needed

    Dave Weaver Guest

    <> wrote:
    >
    > 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"), ...
     
    Dave Weaver, Aug 9, 2005
    #10
  11. perl_help_needed wrote:
    > 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
    }
     
    William James, Aug 10, 2005
    #11
  12. William James wrote:
    > perl_help_needed wrote:
    >> 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


    There must be some misunderstanding here...

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Aug 10, 2005
    #12
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. C
    Replies:
    1
    Views:
    462
    Sunil TG [MVP]
    Oct 29, 2003
  2. Philip Townsend

    Determining date ranges

    Philip Townsend, Nov 6, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    333
    Philip Townsend
    Nov 6, 2003
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,370
    Michael Borgwardt
    May 30, 2004
  4. Replies:
    11
    Views:
    454
    =?ISO-8859-1?Q?Ricardo_Ar=E1oz?=
    Sep 7, 2007
  5. Newb Newb

    how to iterate on date ranges

    Newb Newb, Jan 28, 2009, in forum: Ruby
    Replies:
    2
    Views:
    151
    Rob Biedenharn
    Jan 28, 2009
Loading...

Share This Page