How can I take the current epoch time from perl and find the epoch time from 6 months ago?
I need to compare the create date of a file to see if it 6 months or older.
How can I take the current epoch time from perl and find the epoch time from 6 months ago?
I need to compare the create date of a file to see if it 6 months or older.
The difference can be calculated using DateTime
:
use DateTime;
my $dt = DateTime->now; # or if you have epoch: DateTime->from_epoch( 'epoch' => $epoch );
$dt->subtract( DateTime::Duration->new( 'months' => 6 ) );
The Date::Calc package has functions for that. Use Date_to_Time and Time_to_Date to convert to/from epoch time, and use Add_Delta_YM to add -6 months.
Rough and ready?
perl -le '$sixm = 30.5*6; for ( glob("*") ) { print "delete $_" if -M > $sixm }'