Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: determining work hours between 2 dates

by mojotoad (Monsignor)
on Jun 13, 2006 at 20:35 UTC ( #555122=note: print w/replies, xml ) Need Help??


in reply to determining work hours between 2 dates

Here's one way using DateTime.pm and DateTime::Event::Cron, though it does not take into account holidays and assumes Mon-Fri 8 hrs per day. <shrug> :
use strict; use warnings; use DateTime; my $start_date = DateTime->now(); my $end_date = $start_date + DateTime::Duration->new(months => 2); print $start_date->datetime, "\n", $end_date->datetime, "\n\n"; use DateTime::Event::Cron; my $crontab = '0 0 * * 1-5'; my $set = DateTime::Event::Cron->from_cron( cron => $crontab, start => $start_date, before => $end_date # to include $end_date, use 'end' rather than 'before' ); my @weekdays = $set->as_list; print scalar @weekdays, " weekdays : ", scalar @weekdays * 8, " work h +ours\n";

Cheers,
Matt

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2020-07-08 10:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?