Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: Prior Date

by suaveant (Parson)
on Oct 03, 2007 at 13:51 UTC ( [id://642404]=note: print w/replies, xml ) Need Help??


in reply to Re: Prior Date
in thread Prior Date

Except the OP specified no weekends... I looked briefly at DateTime but didn't see anything for business days... but there must be something.

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

Replies are listed 'Best First'.
Re^3: Prior Date
by Anonymous Monk on Oct 03, 2007 at 14:55 UTC
    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; } }
      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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-24 01:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found