use POSIX qw(strftime); sub TimeStamp { my $f = shift; my @formats = (undef, '%Y-%m-%d %H:%M:%S', '%m%d%Y', '%y%m%d', '%d%m%y', '%Y%m%d%H%M%S', '%Y%m%d', '%d/%m/%Y. %H:%M:%S', '%Y%m%d%H%M', '%d/%m/%Y', ); return strftime($format[$f], localtime); }