Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^4: Adding Days To YYYYMMDD Date Format

by justin423 (Initiate)
on Aug 10, 2012 at 16:49 UTC ( #986772=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Adding Days To YYYYMMDD Date Format
in thread Adding Days To YYYYMMDD Date Format

I have a similar issue. Is there a way to construct a for loop that will generate dates in format YYYMMDD starting on the first business date of the year and skip Saturdays and Sundays?

Example, 20120103 20120104 20120105 20120106 20120109 20120110 20120111 20120112 etc.


Comment on Re^4: Adding Days To YYYYMMDD Date Format
Re^5: Adding Days To YYYYMMDD Date Format
by jdporter (Canon) on Aug 10, 2012 at 17:46 UTC

    Sounds like a job for Date::Manip, which is kind of the "kitchen sink" of date modules.

    Date::Manip::Date::is_business_day would probably do the trick. It also has a 'holiday' method which could let you skip holidays as well, if you wanted to.

    Otherwise, search cpan for other possibilities.

Re^5: Adding Days To YYYYMMDD Date Format
by tobyink (Abbot) on Aug 10, 2012 at 21:49 UTC
    use 5.010; use strict; use warnings FATAL => qw(all); use DateTimeX::Auto qw(:auto); { # slightly evil, but works... package DateTime; use overload '~~', sub { $_[0]->ymd eq $_[1]->ymd } } my $not_business_days = [ sub { $_[0]->day_abbr =~ /^S/ }, # weekends qw( 2012-01-02 2012-04-06 2012-04-09 2012-05-07 2012-06-04 2012-06-05 2012-08-27 2012-12-25 2012-12-26 ), ]; my $date = '2012-01-01'; my $end = '2013-01-01'; while ($date < $end) { say $date->ymd("") unless $date ~~ $not_business_days; $date->add(days => 1); }
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2014-12-19 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (70 votes), past polls