Perl Date::Simple
前に使おうと思って機会を逸しローカルに残していたDate::Simpleを用いたソース。せっかくなので貼っておく。
use Date::Simple; $today = Date::Simple->new; $firstDate = firstDateOfMonth( \$today ); # 月初日 $lastDate = lastDateOfMonth( \$today ); # 月末日 sub firstDateOfMonth { my ($targetDate) = @_; Date::Simple->new( $$targetDate->format("%Y"), $$targetDate->format("%m"), 1 ); } sub lastDateOfMonth { my ($targetDate) = @_; Date::Simple->new( $$targetDate->format("%Y"), $$targetDate->format("%m"), Date::Simple::days_in_month( $$targetDate->format("%Y"), $$targetDate->format("%m") ) ); }