Some Date::Manip (mainly used for day of the week type stuff): $companystartdate = &ParseDate("today"); # returns 2000082415:40:44 format $companystartdate =~ s/^(....)(..).+/$1-$2-01/; # build 2000-08-01 Some SQL: my $statement = "select * from charges where (UserId='$userhash{'UserId'}' AND (Date BETWEEN '$start' AND DATE_ADD('$start', interval 6 day) ) ) order by ClientGroupId,ClientId,Date"; and my $monthstart = substr($sqlstartdate,0,8) . "01"; # 2000-08-01 my $monthend = "DATE_SUB( ( DATE_ADD('$monthstart',interval 1 month) ), Interval 1 day)"; # 1mo less 1dy. too many parens? my $statement="select sum(Hours) from charges where (UserId='$userhash{'UserId'}' and ClientId='$client' and FeeType='$fee' and Date between '$monthstart' and $monthend ) group by UserId";