use Time::Local; ### this will get me the Unix time ### for the last day in May # get today's month and year my ($m, $y) = (localtime)[4,5]; # get next month's month and year my ($nm, $ny) = ($m == 11) ? (0, $y+1) : ($m+1, $y); # get noon on the first of next month my $next_month_noon = timelocal(0,0,12, 1,$nm,$ny); # subtract a day from it (86400 seconds) my $month_last_day = $next_month_noon - 86400; #### # my code above, as a function sub lastday_time { use Time::Local; # I never do this in real code # I put module uses at the top of # the entire program, not each sub # arguments are assumed to be in "human" terms my ($m, $y) = @_; $m--, $y -= 1900; # perl-ify them my ($nm, $ny) = ($m == 11) ? (0,$y+1) : ($m+1,$y); # return the first of next month, minus one day return timelocal(0,0,12, 1,$nm,$ny) - 86400; } sub is_last_of_month { # arguments are "human" # lastday_time() subtracts 1 from $m and 1900 from $y my ($d, $m, $y) = @_; my $last_day = (localtime lastday_time($m,$y))[3]; # fixed that last line -- I had $d, meant $m return $d == $last_day; }