<?xml version="1.0" encoding="windows-1252"?>
<node id="556225" title="Determining the dayname for the last day of any given month" created="2006-06-19 07:10:26" updated="2006-06-19 03:10:26">
<type id="115">
perlquestion</type>
<author id="483556">
McDarren</author>
<data>
<field name="doctext">
This afternoon, a co-worker asked me: "how do i get the last day of the month in perl ?"

&lt;p&gt;After clarifying with him that he wanted the "name of the day of the last day of any given month/year", and then having a quick fossick about on CPAN, I threw the following example together using [cpan://Calendar::Functions]: 

&lt;code&gt;
#!/usr/bin/perl -w
use strict;
use Calendar::Functions qw(month_days dotw dotw3);

while (1) {
    print "Enter year (yyyy) and month (mm), separated by a space:";
    chomp(my $input = &lt;STDIN&gt;);
    last if !$input;

    my ($year, $month) = split / /, $input;
    my $dayname = dotw(dotw3(month_days($month, $year), $month, $year));

    print "The last day of $month/$year will be a $dayname\n";
}
&lt;/code&gt;

&lt;p&gt;I'm curious to know how others would approach this little task?

&lt;p&gt;&lt;em&gt;(There are a few related [id://1837|Q&amp;A's], - [id://97120|this one] in particular - but none are quite the same)&lt;/em&gt;

&lt;p&gt;&lt;b&gt;Update: &lt;/b&gt; many thanks for all the replies. As always - TIMTOWTDI. However, on this occassion - for pure simplicity - the &lt;b&gt;pony&lt;/b&gt; has to go to [herkum] for his [cpan://DateTime] [id://556231|solution] :)

&lt;p&gt;Thanks,&lt;br&gt;
Darren :)</field>
</data>
</node>
