Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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.

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://556255]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2018-01-18 12:03 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (211 votes). Check out past polls.