Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Excel stores dates as sequential numbers known as serial values. Excel stores times as decimal fractions because time is considered a portion of a day. Dates and times are values and so you can add, subtract, and include dates and times in other calculations.
For example, to determine the difference between two dates, you can subtract one date from the other. You can view a date as a serial value and a time as a decimal fraction by changing the format of the cell that contains the date or time to General format.
#!/usr/bin/perl -w
use strict;
my $excel_time = 0.398865741; #9:34:22
my $sec_in_day = 86400;
my $min_in_day = 1440;
my $hour_in_day = 24;
#int function just truncates decimals
my $h = int($excel_time * $hour_in_day); #hours are easy
my $m = int(($excel_time * $min_in_day) - $h * 60); #minuets, minus the hour portion
my $s = int(($excel_time * $sec_in_day) - (($h * 60 * 60) + $m * 60)); #seconds minus the hours and min portion
print "$excel_time --> $h:$m:$s \n";