in reply to Working with multiple records with different dates

A somewhat elaborate but thorough way to do this is to convert all of the dates to Unix/Perl timecode values. This will allow you to distinguish values to 1 second in an easily-sortable format (numbers). The code to handle time of day is a bit tricky. Maybe you do not need that part. Here is the code I use.

# Converting date/time info to Unix time code use Time::Local; # timelocal() returns a Unix time code number # Function timelocal() takes a 6-element list, the same as the first # six arguments of the localtime function. If you have # $timecode = timelocal @list; # then mday = list[3] = 1..31 # mon = list[4] = 0..11 # yr = list[5] = year-1900 # Assume you have "hr:min:sec am/pm" as variables # $arghr, $argmin, $argsec, $ampm If the time-of-day # does not matter, I usually set them as "12:1:1 am", # (just after noon) to avoid being near a day changeover. $arghr = $1; $argmin = $2; $argsec = $3; $ampm = $4; # Assume you have "day,mon,yr" as variables # $argday, $monname, $argyr # "day" = 1 .. 31 # "mon" = Jan .. Dec # and 2-digit (21st century) year $argday = $1; $monname = ucfirst $2; $argyr = $3; # Given the above seven arguments, the following code # will produce the corresponding Unix (Perl) timecode value %monhash = ( "Jan" =>1, "Feb" =>2, "Mar" =>3, "Apr" =>4, "May" =>5, "Jun" =>6, "Jul" =>7, "Aug" =>8, "Sep" =>9, "Oct" =>10, "Nov" =>11, "Dec" =>12 +); $hrmin = 0; $hrmax = 23; if ( $ampm ne "" ) { $hrmin = 1; $hrmax = 12; $addhrs = 0; if ( $ampm =~ /^p/ ) { $addhrs = 12; } } if ( $arghr < $hrmin or $arghr > $hrmax ) { die "Hours portion of date argument '$arghr' out of range.\n"; } if ( $ampm ne "" ) { if ( $arghr == 12 ) { $arghr = 0; } $arghr += $addhrs; } if ( $argmin < 0 or $argmin > 59 ) { die "Minutes portion of date argument '$argmin' out of range.\n"; } if ( $argsec < 0 or $argsec > 59 ) { die "Seconds portion of date argument '$argsec' out of range.\n"; } print "The time arg is $arghr:$argmin:$argsec\n"; if ( not defined $monhash{ $monname } ) { die "Could not parse month portion '$monname' of date argument.\n"; } $argmon = $monhash{ $monname }; $argyear = 1900 + $argyr; $argtime = timelocal( $argsec, $argmin, $arghr, $argday, $argmon, $argyear - 1900 );