Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

(zdog) Re: Weird Date::Calc behavior; Bug?

by zdog (Priest)
on Apr 19, 2001 at 08:51 UTC ( #73759=note: print w/ replies, xml ) Need Help??


in reply to Weird Date::Calc behavior; Bug?

You cannot assign a scalar to an array that way. You should instead split the scalar up like so:

#!/usr/bin/perl -w #find-missing-files.pl use strict; use Date::Calc qw ( Delta_Days Add_Delta_Days ); my (@start, @stop); @start = split (/-/, $ARGV[0]); print "@start\n"; @stop = split (/-/, $ARGV[1]); print "@stop\n"; for ( my $i = 0; $i <= Delta_Days(@start, @stop); $i++ ) { my @date = Add_Delta_Days (@start, $i); printf ("%4d-%02d-%02d\n", @date); }
Update: You can also do something like:

$from =~ s/-/,/g; $to =~ s/-/,/g; @start = eval ($from); @stop = eval ($to);

Zenon Zabinski | zdog | zdog7@hotmail.com


Comment on (zdog) Re: Weird Date::Calc behavior; Bug?
Select or Download Code
Re^2: Weird Date::Calc behavior; Bug?
by Anonymous Monk on Mar 06, 2006 at 18:02 UTC
    I have a different problem - but the title of the thread and the code are similar...

    Here's the code...

    #!/usr/bin/perl use Date::Calc qw( Delta_Days Add_Delta_Days); use strict; my ($year1,$month1,$day1) = (2006,3,6); my ($year2,$month2,$day2) = (1997,5,8); print"Todays date is $day1\/$month1\/$year1\n"; print"The date in the past is $day2\/$month2\/$year2\n"; # Get the difference in days between the two dates my $daysdiff = Delta_Days($year2,$month2,$day2,$year1,$month1,$day1); # Add the difference to 01/01/0001 to get the long date my ($diffyear,$diffmonth,$diffday) = Add_Delta_Days(1,1,1,$daysdiff); print"The difference between $day2\/$month2\/$year2 and $day1\/$month1 +\/$year1 is ...\n"; print"$diffyear Years, $diffmonth Months and $diffday Days\n";
    The output :
    $ ./view_space.pl Todays date is 6/3/2006 The date in the past is 8/5/1997 The difference between 8/5/1997 and 6/3/2006 is ... 9 Years, 10 Months and 30 Days

    Now, using my fingers, I make the difference between the dates 8/5/1997 and 6/3/2006 ...
    8 Years, 9 months and 2 days.

    Why the different result from Date::Calc? Am I doing something wrong? It's not even close!!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (12)
As of 2014-09-30 19:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (381 votes), past polls