For date calculations use the cpan module: Date::Calc and possibly Date::Parse

Here's a quick and dirty script that takes the dates you specified and prints the difference in days between them. Note that there are differences between how Date::Parse treats month ranges and how Date::Calc does.

use Date::Parse; use Date::Calc qw(Delta_Days); use strict; my $base = 'Jan 1, 1980'; my $start = 'Feb 1, 1981'; my $end = 'Feb 5, 1982'; print days_diff($start, $base) . "\n"; # 397 print days_diff($end, $base) . "\n"; # 766 sub days_diff { my $minuend = shift; my $subtrahend = shift; my (undef,undef,undef,$d2,$m2,$y2,undef) = strptime($minuend); my (undef,undef,undef,$d1,$m1,$y1,undef) = strptime($subtrahend); return Delta_Days($y1, $m1+1, $d1, $y2, $m2+1, $d2); } 1; __END__

In reply to Re: date ranges as days by wind
in thread date ranges as days by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.