Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Timed event

by data67 (Monk)
on Nov 22, 2001 at 03:06 UTC ( #126884=perlquestion: print w/replies, xml ) Need Help??

data67 has asked for the wisdom of the Perl Monks concerning the following question:

Hey all, I was trying to do some "stuff" if a condition was tru based on time.
Here is how I was hoping it will work:
if Today eq 5days_lest_then_end_of_month; do stuff else skipp

I know it seems simple but what if i told you that those five days have to be business days.
Look at what i had so far thanks to a friend:-)

#!/usr/local/bin/perl -w use diagnostics; use strict; use Date::Calc qw(:all); use Date::Calendar; use Date::Calendar::Profiles qw( $Profiles ); my $cal = Date::Calendar->new( $Profiles->{'DE-NW'} ); # or wherever y +ou are my @today = Today(); my @date = Add_Delta_YM($today[0],$today[1],1, 0,1); # first of next m +onth my $date = $cal->add_delta_workdays(@date,-5); # 5 business days befor +e that #my $date = $cal->add_delta_workdays(@date,-5); # 5 business days befo +re that $date->date_format(2); print "date = $date\n"; print "today = @today\n";
This prints out:
date = Fri 23-Nov-2001 today = 2001 11 21
So i guess the question is that all i need is to somehow rearrange these dates in a standard form so i can use it in that conditional. As always, any suggestions will be very helpful...Thanks

Replies are listed 'Best First'.
Re: Timed event
by kwoff (Friar) on Nov 22, 2001 at 03:26 UTC
    Try, with functions (according to `perldoc`) Date_NextWorkDay(), Date_PrevWorkDay(), Date_IsWorkDay(), Date_NearestWorkDay().
      Date::Manip also allows such niceties as accepting "-5 business days" for a valid date when parsing date differences; this also takes into account hollidays and other such nonesense.
Re: Timed event
by data67 (Monk) on Nov 22, 2001 at 03:22 UTC
    oh by the way if you modify the $date->date_format(*) to 5 it prints:  date = 20011121

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://126884]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (1)
As of 2022-06-26 05:31 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (83 votes). Check out past polls.