Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Calc last friday of month

by ikegami (Pope)
on Feb 03, 2009 at 04:50 UTC ( #740899=note: print w/ replies, xml ) Need Help??

in reply to Calc last friday of month

  1. Find the day of the week of the first day of the month (using Date::Calc, DateTime, localtime or whatever).

  2. Find the number of days to add or subtract.

    Days to first Monday:

    $days_to_first_monday = ($dow + 7 - 1) % 7;

    Days to previous Friday:

    $days_to_last_friday = ($dow + 7 - 5) % 7 - 7;

    In both case, $dow is expected to hold 1..7 for Mon..Sun or 0..6 for Sun..Sat

  3. Use Date::Calc or DateTime to perform the math.

Comment on Re: Calc last friday of month
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2015-11-27 21:27 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (732 votes), past polls