Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Split date range into 3 equal parts

by tobyink (Abbot)
on Dec 08, 2011 at 09:37 UTC ( #942380=note: print w/ replies, xml ) Need Help??


in reply to Split date range into 3 equal parts

Don't know about Date::Calc, but using DateTime...

use DateTimeX::Auto 0.003 qw/:auto/; my $from = '2010-06-01'; my $to = '2011-01-01'; my $diff = $to->delta_days($from)->in_units('days'); my $mid_date_1 = $from->clone->add(days => $diff/3); my $mid_date_2 = $to->clone->subtract(days => $diff/3); print <<OUT; from: $from mid 1: $mid_date_1 mid 2: $mid_date_2 to: $to OUT

UPDATE: Just released 0.003 of DateTimeX::Auto because the script above was crashing on add and subtract.


Comment on Re: Split date range into 3 equal parts
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-09-17 21:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (99 votes), past polls