Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Trouble with Dates

by poj (Vicar)
on Jul 09, 2013 at 21:47 UTC ( #1043384=note: print w/ replies, xml ) Need Help??

in reply to Trouble with Dates


use strict; use warnings; use Date::Calc qw( Delta_Days Today Days_in_Month ); my $cnt = 0; # work out end of current month my ($y,$m,$d) = Today(); my $mth_end = sprintf "%04d,%02d,%02d",$y,$m,Days_in_Month($y,$m); while (<DATA>) { my @dates = split '\s+', $_; $cnt++; # fill empty dates with month end my @ymd1 = split ',',$dates[0] //= $mth_end; my @ymd2 = split ',',$dates[1] //= $mth_end; my $diff = Delta_Days(@ymd1, @ymd2); print "$dates[0] $dates[1] $diff \n"; } print $cnt, "\n";

Comment on Re: Trouble with Dates
Download Code
Replies are listed 'Best First'.
Re^2: Trouble with Dates
by rruser (Acolyte) on Jul 10, 2013 at 18:48 UTC

    This worked great!! thx poj

    if i wanted to find previous month's last day how would i go about that..thx

      To get last day of previous month add -1 days to the 1st of the current month.
      #perl use strict; use Date::Calc qw( Delta_Days Today Days_in_Month Add_Delta_Days); # add Add_Delta_Days my ($y,$m,$d) = Today(); # Add_Delta_Days #($year,$month,$day) = Add_Delta_Days($year,$month,$day,$Dd); my $prev_mth_end = sprintf "%04d,%02d,%02d", Add_Delta_Days($y,$m,1,-1); print $prev_mth_end;
      All the function are documented in Date::Calc.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1043384]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2015-11-28 19:44 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (744 votes), past polls