perl é útil
use Time::Piece;
my $date1 = "2014-NOV-0620:59:59";
my $date2 = "2014-12-31";
my $datetime1 = Time::Piece->strptime($date1, "%Y-%b-%d%H:%M:%S");
my $datetime2 = Time::Piece->strptime($date2, "%Y-%m-%d");
if ($datetime1 < $datetime2) {
print "$date1 is earlier than $date2\n";
}
elsif ($datetime1 > $datetime2) {
print "$date1 is later than $date2\n";
}
else {
print "$date1 is equal to $date2\n";
}
GNU awk:
gawk '
function parse_date_fmt_1(date, epoch, regex, month) {
regex = "([[:digit:]]{4})-([[:alpha:]]{3})-([[:digit:]]{2})([[:digit:]]{2}):([[:digit:]]{2}):([[:digit:]]{2})"
if (match(date, regex, m)) {
month = index("..JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC", toupper(m[2])) / 3
epoch = mktime(m[1] " " month " " m[3] " " m[4] " " m[5] " " m[6])
}
return epoch
}
function parse_date_fmt_2(date, epoch, regex) {
regex = "([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2})"
if (match(date, regex, m)) {
epoch = mktime(m[1] " " m[2] " " m[3] " 0 0 0")
}
return epoch
}
BEGIN {
date1 = "2014-NOV-0620:59:59"
print parse_date_fmt_1(date1)
date2 = "2014-12-31"
print parse_date_fmt_2(date2)
}
'