in reply to Re^2: Prior Date
in thread Prior Date

I have this, but I can't figure it ou how to pass the values for the dates using a variable, can anyone try that?

#!/usr/bin/perl use strict; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); use DBI; use Date::Pcalc qw(:all); print header(); my $s_date="2007,09,27"; my $e_date="2007,10,3"; my @range = &Delta_Business_Days($s_date,$e_date); foreach my $date (@range) { print Date_to_Text(@{$date}), "\n"; # It breaks here... print "**$date**<br>"; } sub Delta_Business_Days { my(@date1) = (@_)[0,1,2]; my(@date2) = (@_)[3,4,5]; my($minus,$result,$dow1,$dow2,$diff,$temp); $minus = 0; $result = Delta_Days(@date1,@date2); if ($result != 0) { if ($result < 0) { $minus = 1; $result = -$result; $dow1 = Day_of_Week(@date2); $dow2 = Day_of_Week(@date1); } else { $dow1 = Day_of_Week(@date1); $dow2 = Day_of_Week(@date2); } $diff = $dow2 - $dow1; $temp = $result; if ($diff != 0) { if ($diff < 0) { $diff += 7; } $temp -= $diff; $dow1 += $diff; if ($dow1 > 6) { $result--; if ($dow1 > 7) { $result--; } } } if ($temp != 0) { $temp /= 7; $result -= ($temp << 1); } } if ($minus) { return -$result; } else { return $result; } }

Replies are listed 'Best First'.
Re^4: Prior Date
by suaveant (Parson) on Oct 03, 2007 at 17:26 UTC
    I still think Date::Manip is more what you want... for example:
    use Date::Manip; $date1 = ParseDate("20071001"); $date2 = ParseDate("20070926"); print DateCalc($date1,"- 3 business days"),"\n"; print DateCalc($date1,$date2,\$err),"\n"; # regular mode... 5 days print DateCalc($date1,$date2,\$err,2),"\n"; #business mode... 3 days

                    - Ant
                    - Some of my best work - (1 2 3)

      Hi, tried your code here getting this:
      Software error: ERROR: Date::Manip unable to determine Time Zone. at C:/Perl/site/lib/Date/Manip.pm line 3645 Date::Manip::Date_TimeZone called at C:/Perl/site/lib/Date/Manip.p +m line 684 Date::Manip::Date_Init() called at C:/Perl/site/lib/Date/Manip.pm +line 1454