# calculate data on run time to even previous hour my $dt = POSIX::strftime("%Y-%m-%d", localtime( shift( @_ ) || time ) ); my $hr = POSIX::strftime("%H", localtime( shift( @_ ) || time ) ); my $bhr = $hr - 1; my $bdt = "$dt $bhr:00:00"; # this one comes from the DB but it looks like this my $db_date = "2015-04-08 12:42:13"; # this is what I want to do if ($db_date <= $bdt) { # process }