use warnings; use strict; # test routine for my $y (2001..2002){ for my $m (1,6,12){ for my $d (1,15,16,31){ print "$d\t$m\t$y = ".newrelease($d,$m-1,$y-1900)."\n"; } } print "\n"; } sub newrelease { #my ($day,$month,$year) = (localtime)[3,4,5]; my ($day,$month,$year) = @_; # testing # make normal $year+=1900; $month+=1; # return values my ($start_date,$end_date); # logic if ($day > 15){ # easy one same month $month = sprintf "%02d",$month; $start_date = $year.$month."01"; $end_date = $year.$month."15"; } else { # day is 15 or less use previous month # if now jan then prev month is dec last year if ($month == 1){ --$year; $month=12; } else { $month = sprintf "%02d",$month-1; } $start_date = $year.$month."16"; $end_date = $year.$month."31"; } return "$start_date to $end_date"; }