on Thu, 15 Aug 2002 05:05:15 GMT, Shane Laffin wrote: > How do I compare two dates in the format: > > Thu Aug 15 2002 15:12:02 > > to return if one date is higher than the other. > > Does anyone have any ideas on suitable modules, most > the date modules I have looked at dont deal with this > date format.
Roll your own: #! perl -w use strict; my $date1 = "Thu Aug 15 2002 15:12:02"; my $date2 = "Wed Jul 10 2002 10:10:10"; print cmp_dates($date1, $date2), "\n"; # prints 1 print cmp_dates($date2, $date1), "\n"; # prints -1 print cmp_dates($date1, $date1), "\n"; # prints 0 BEGIN { my %months = (Jan => '01', Feb => '02', Mar => '03', Apr => '04', May => '05', Jun => '06', Jul => '07', Aug => '08', Sep => '09', Oct => '10', Nov => '11', Dec => '12' ); sub cmp_dates { my @d1 = (split " ", shift)[3,1,2,4]; my @d2 = (split " ", shift)[3,1,2,4]; $d1[1] = $months{$d1[1]}; $d2[1] = $months{$d2[1]}; return (join "", @d1) cmp (join "", @d2); } } -- felix -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]