Ready made module in Perl to convert epoch time to DB2 or Human timestamp formats (YYYY-MM-DD HH:MM:SS)

Write a function convertEpochToHumanTimestamp and call this from the required sub.

# Function : convertEpochToHumanTimestamp
# Description : Convert Epoch into a formatted time suitable for insertion into a Human database timestamp
# column. The output format is “YYYY-MM-DD HH:MM:SS”

my $inputEpoch = shift;

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($inputEpoch);
$mon++;
$year = $year + 1900;
my $humanTime = sprintf (“%04d-%02d-%02d %02d:%02d:%02d”, $year, $mon, $mday, $hour, $min, $sec);

return ($humanTime);

 

+ Recent posts