use strict; use POSIX qw(strftime); sub day_before { my ($ts) = @_; my $ts_now = strftime '%Y%m%d', $ts; $ts -= 22*60*60 while strftime('%Y%m%d', $ts) eq $ts_now; return strftime '%Y%m%d', $ts; }; print day_before(time);