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 );

In reply to Re: Working with multiple records with different dates by LloydRice
in thread Working with multiple records with different dates by rruser

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.