Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: determining work hours between 2 dates

by mojotoad (Monsignor)
on Jun 13, 2006 at 20:35 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://555122]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found