# script name mysql-date-fixer # NB: Date::Manip is great but it is slow, and this is fun code # but just something i did to play with Date::Manip and not # that polished use Date::Manip; use warnings; use strict; my $date; my $date_thing_to_check = join(' ', @ARGV); unless ( $date_thing_to_check ) { print "What date are you trying to figure out?\n\t"; chomp ($date_thing_to_check = ); } # string of numbers not like 200304242116, we'll call it epoch secs if ( $date_thing_to_check =~ /^(?!19|20)\d{7,10}$/ ) { $date = ParseDateString("epoch $date_thing_to_check"); $date = ParseDate($date); } else { # something date-ish, ParseDate is very forgiving $date = ParseDate($date_thing_to_check); } unless ( $date ) { die "I couldn't figure that one out...\n", "\tPlease try again with simplified input, ", "write numbers in Arabic.\n"; } # a mySQL format, YYYY-MM-DD HH:MM:SS print UnixDate( $date,"%Y-%m-%d %H:%M:%S"), "\n";