----- Original Message ----- 
From: "Jan Eden" <[EMAIL PROTECTED]>
Newsgroups: perl.beginners
To: "Perl Lists" <[EMAIL PROTECTED]>
Sent: Wednesday, April 21, 2004 1:29 PM
Subject: Date calculation


Hi,

I need to find the number of days between two dates. The Perl Cookbook
provides this solution:

use Date::Calc qw(Delta_Days);
@bree = (1981, 6, 16);      # 16 Jun 1981
@nat  = (1973, 1, 18);      # 18 Jan 1973
$difference = Delta_Days(@nat, @bree);

But there's a hook: I need to calculate a room price based on the number of
days, where a day costs $80 during summer (July 1 through September 15) and
$55 otherwise (September 16 through June 30).

Since people can book a room for any interval, I somehow have to integrate
the dividing day and month values


Hello Jan
Maybe something like this would do what you want   :-)

#!/usr/bin/perl
use strict;
use warnings;
use Date::Calc qw/Delta_Days Date_to_Days Add_Delta_Days/;

my $beg = Date_to_Days(2004, 7, 1);
my $end = Date_to_Days(2004, 9, 15);

my @chk_in = (2004, 6, 28);
my @chk_out = (2004, 7, 5);

my $j = Delta_Days(@chk_in,@chk_out);

for ( my $i = 0; $i <= $j; $i++ ){
     my @date = Add_Delta_Days(@chk_in,$i);
     printf("%4d-%02d-%02d\t", @date);
     my $day = Date_to_Days(@date);
     print $day >= $beg && $day <= $end ? "\$80.00\n" : "\$55.00\n";
}

I took this example from Dtae::Calc man pages
        - perldoc Date::Calc

The output was
2004-06-28      $55.00
2004-06-29      $55.00
2004-06-30      $55.00
2004-07-01      $80.00
2004-07-02      $80.00
2004-07-03      $80.00
2004-07-04      $80.00
2004-07-05      $80.00


HTH,
Chris




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to