We don't bite newbies here... much PerlMonks

### Date Calculation

by palette (Scribe)
 on Jan 30, 2007 at 14:33 UTC Need Help??

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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Date Calculation
by philcrow (Priest) on Jan 30, 2007 at 14:38 UTC
You could try Date::Calc. From its docs:

8) How can I add a week offset to a business date (including across year boundaries)?
```             use Date::Calc qw( Business_to_Standard Add_Delta_Days

@temp = Add_Delta_Days(@temp, \$week_offset * 7);

Phil

A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Date Calculation
by davorg (Chancellor) on Jan 30, 2007 at 14:40 UTC

How do you define a business day? Is it weekdays? Or do you need to take into account public holidays and things like that?

Here's a naive approach that just leaves you needing to define an is_business_day() subroutine which takes a time (as an epoch seconds value) as an argument.

```my \$today = time;

while (1) {
\$time += 24 * 60 * 60; # add a day

}

print scalar localtime \$time;

Update: As ikegami correctly points out below, there's a potential bug in this program if it's run across days that don't contain 24 hours (i.e. when switching to or from daylight saving time). The fix is to normalise the time to noon (assuming that timezone changes always occur overnight). This change is left as an exercise for the reader.

Not all days have 24 hours.
Re: Date Calculation
by davidrw (Prior) on Jan 30, 2007 at 15:19 UTC
here's a Date::Calc solution -- assumes "business day" is just M-F, so adding 10 just needs to add in the two weekends as well, so is simply:
```use Date::Calc qw/Add_Delta_Days/;
my @start = ( \$year, \$month, \$day );
my @end = Add_Delta_Days( @start, 14 );
If you want to take into account holidays, see the "10) How can I calculate the last business day (payday!) of a month?" example in the Date::Calc docs for reference.
Re: Date Calculation
by liverpole (Monsignor) on Jan 30, 2007 at 14:39 UTC
Hi palette,

Look at Date::Calc.  There is a function Add_Delta_Days which may be close to what you need.

Additionally, there are some functions in it which deal specifically with business days:

```      check_business_date

s''(q.S:\$/9=(T1';s;(..)(..);\$..=substr+crypt(\$1,\$2),2,3;eg;print\$..\$/
Re: Date Calculation
by Cody Pendant (Prior) on Jan 31, 2007 at 00:38 UTC

(\$_='kkvvttuu bbooppuuiiffss qqffssmm iibbddllffss')
=~y~b-v~a-z~s; print
Re: Date Calculation
by gube (Parson) on Jan 30, 2007 at 15:06 UTC
Hi,

Updated : Sorry, Mistaken i suggest to add days i missed to read the word buisness days.

Use DateCalc module. DateCalc

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://597370]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2023-05-31 10:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?