Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: Adding Days To YYYYMMDD Date Format

by justin423 (Scribe)
on Aug 10, 2012 at 16:49 UTC ( [id://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

Replies are listed 'Best First'.
Re^5: Adding Days To YYYYMMDD Date Format
by jdporter (Paladin) 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 (Canon) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://986772]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found