G'day Rajini,

S, Rajini (STSD) wrote:

> I am new to Perl Programming and have a query in perl. 
> 
> In perl is there any system defined functions to find out the Differences in 
> dates. 
> 
> Eg : 
> 
> Date 1 -> 26-Jan-2009
> Date 2 -> 14-Jan-2009 
> 
> So the difference between two dates is 12 days. 

There aren't any Perl built-in functions to do this.  Fortunately there are a
whole range of Date modules on CPAN that might be suitable for your needs.  You
will need to install whichever one(s) you choose on your system if they are not
already there.  There is an answer to how to find out what is installed on your
system if you do:

        perldoc -q installed

So, to find out what Date modules exist you'd search CPAN:

        http://search.cpan.org/search?query=date&mode=all

In particular I'd suggest looking at Date::Simple


        #!/usr/bin/perl -w
        use strict;
        use Date::Simple qw(date);

        # Difference in days between two dates:
        my $diff = date('2001-08-27') - date('1977-10-05');

If you need to convert from your date format '26-Jan-2009' to the format that
Date::Simple will accept then you might want to look at the Date::Parse module
as well.

There are other Date modules that might be better suited, and I encourage you to
look at them too.

All the best,

        Jacinta

-- 
   ("`-''-/").___..--''"`-._          |  Jacinta Richardson         |
    `6_ 6  )   `-.  (     ).`-.__.`)  |  Perl Training Australia    |
    (_Y_.)'  ._   )  `._ `. ``-..-'   |      +61 3 9354 6001        |
  _..`--'_..-_/  /--'_.' ,'           | cont...@perltraining.com.au |
 (il),-''  (li),'  ((!.-'             |   www.perltraining.com.au   |

Reply via email to