Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Determining the dayname for the last day of any given month

by ambrus (Abbot)
on Jun 19, 2006 at 13:58 UTC ( #556255=note: print w/ replies, xml ) Need Help??


in reply to Determining the dayname for the last day of any given month

The trick is that the last day of the month is the day before the first day of next month. So here's an example solution with Date::Manip:

use Date::Manip; $input = "June 2006"; # these also work: #$input = "2006 june"; #$input = "today"; #$input = "June 2006"; $thismonth = UnixDate($input, "%B %Y"); $lastofmonth = DateCalc($thismonth, "+1 month -1 day"); $dow_lastofmonth = UnixDate($lastofmonth, "%A\n"); print $dow_lastofmonth;
This prints Friday.


Comment on Re: Determining the dayname for the last day of any given month
Select or Download Code
Re^2: Determining the dayname for the last day of any given month
by davorg (Chancellor) on Jun 19, 2006 at 14:04 UTC

      I am not convinced by that node.

      I know that Date::Manip has disadvantages and is not always the module to use, but I don't see why it's wrong here. I don't think this task needs high speed or full i18n. I do like Date::Manip for such quick tasks like this, because it's easy to use.

      You say that the API is not consistent. There's only a handful of functions I have to use, and they aren't inconsistent IMO. (The functions are UnixDate, DateCalc, Date_Cmp, ParseDate, ParseDateDelta.) Having to use a few functions that can do almost anything (ok, I needed timezone conversion once) makes the module very easy to use which is more important than consistency in small and simple tasks like this.

      You are right that the module docs say

      If you're only doing fairly simple date operations (parsing common date formats, finding the difference between two dates, etc.), the other modules will almost certainly suffice.
      but contrary to this I still find the module good for these tasks.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (16)
As of 2014-07-30 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (240 votes), past polls