Various ways to convert Oracle dates ⇔ Perl dates.
# Parse a timestamp, and return it in Perl time format.
#
# Only the order of the numbers is important (year-month-date-hour-minute-second),
# you can use any separators you want. Also, hour/minute/second can be left off.
#
# To generate this in Oracle:
# TO_CHAR(my_time, 'YY/MM/DD HH24:MI:SS')
# TO_CHAR(my_time, 'YY-MM-DD HH24:MI')
#
# To generate this in MySQL:
# DATE_FORMAT(my_date, '%Y/%m/%d %H:%i:%s')
#
use Time::Local;
sub parse_timegm {
my @timestamp = grep /./, split /\D+/, shift;
push @timestamp, (0)x6; # Pad out, in case seconds / H:M:S are missing
splice @timestamp, 6; # Truncate
$timestamp[1]--; # Why is the month 0-based??
return timegm(reverse @timestamp);
}
sub parse_timelocal {
my @timestamp = grep /./, split /\D+/, shift;
push @timestamp, (0)x6; # Pad out, in case seconds / H:M:S are missing
splice @timestamp, 6; # Truncate
$timestamp[1]--; # Why is the month 0-based??
return timelocal(reverse @timestamp);
}
Method #2:
SELECT ROUND((sysdate + (my_date - to_date('1-1-1970','MM-DD-YYYY')) - sysdate) * 86400) AS my_date_epoch FROM ...
This converts it to an Unix date (epoch date) using only SQL.
(if the actual SQL seems complicated — what it does is convert a date ⇒ interval, and then interval ⇒ number)