Prev: why is child process a negative number?
Next: FAQ 4.68 Why does passing a subroutine an undefined element in a hash create it?
From: Hugh on 22 Apr 2010 22:02 Perl neophyte here. I have a record date in the format mm/dd/yyyy and I want to compare it to another date in the same format. Is there a simple way to accomplish this task? All I want to do is say 'if date1 <= date0' do or don't do something. I've looked, but to no avail. Help please... Thank you in advance, Hugh
From: John W. Krahn on 22 Apr 2010 22:51 Hugh(a)earthlink.net wrote: > Perl neophyte here. > > I have a record date in the format mm/dd/yyyy and I want to compare it to > another date in the same format. Is there a simple way to accomplish this > task? All I want to do is say 'if date1 <= date0' do or don't do > something. I've looked, but to no avail. Help please... if ( join( '', ( split /\//, $date1 )[ 2, 0, 1 ] ) le join( '', ( split /\//, $date0 )[ 2, 0, 1 ] ) ) { do something; } John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway
From: J�rgen Exner on 22 Apr 2010 23:01 Hugh(a)earthlink.net wrote: >I have a record date in the format mm/dd/yyyy and I want to compare it to >another date in the same format. Is there a simple way to accomplish this >task? All I want to do is say 'if date1 <= date0' do or don't do >something. I've looked, but to no avail. Help please... Date::Calc is your friend. Of course, had you used an ISO-8601 compliant format then a simple alphanumerical comparision using 'le' would have been sufficient. jue
From: Tad McClellan on 22 Apr 2010 23:51 Hugh(a)earthlink.net <Hugh(a)earthlink.net> wrote: > I have a record date in the format mm/dd/yyyy Too bad it isn't in a more sensible format, such as yyyy/mm/dd... > and I want to compare it to > another date in the same format. Is there a simple way to accomplish this > task? If they were in yyyy/mm/dd, then $date1 le $date0 would be all you need. But since you seem to be restricted to using a silly date format, the Date::Manip module can help. --------------------------- #!/usr/bin/perl use warnings; use strict; use Date::Manip; my $date0 = '04/01/2010'; my $date1 = '04/02/2010'; if ( Date_Cmp(ParseDate($date0), ParseDate($date1)) <= 0 ) { print "$date0 is less than or equal to $date1\n"; } else { print "$date0 is greater than $date1\n"; } ($date0, $date1) = ($date1, $date0); # swap values, and try it again if ( Date_Cmp(ParseDate($date0), ParseDate($date1)) <= 0 ) { print "$date0 is less than or equal to $date1\n"; } else { print "$date0 is greater than $date1\n"; } --------------------------- -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site.
From: Hugh on 23 Apr 2010 01:13
J�rgen Exner wrote: >Hugh(a)earthlink.net wrote: >>I have a record date in the format mm/dd/yyyy and I want to compare it to >>another date in the same format. Is there a simple way to accomplish this >>task? All I want to do is say 'if date1 <= date0' do or don't do >>something. I've looked, but to no avail. Help please... > >Date::Calc is your friend. > >Of course, had you used an ISO-8601 compliant format then a simple >alphanumerical comparision using 'le' would have been sufficient. > Thanks. Hugh |