Sherlock has asked for the wisdom of the Perl Monks concerning the following question:
The elements within [] are optional characters. For example, 1/1/2001 would be legal, as would 12/12/2001, but not, 12/12/01. The year requires all four digits.[M]M/[D]D/YYYY
As you can see, I'm simply grabbing all the characters up to a "/" and then I go back and cut off the front of the date up to (and including that "/"). Simply put, I grab the month from $oldDate, store it into $oldMonth, and then modify $oldDate to go from MM/DD/YYYY to DD/YYYY. For example, if $oldDate contained 1/12/2001, $oldMonth would contain 1 and $oldDate would contain 12/2001.sub isGreater { my $currDate = $_[0]; my $oldDate = $_[1]; my $currMonth = substr($currDate, 0, index($currDate, "\/")); $currDate = substr($currDate, index($currDate, "\/")+1); my $oldMonth = substr($oldDate, 0, index($oldDate, "\/")); $oldDate = substr($oldDate, index($oldDate, "\/")+1); my $currDay = substr($currDate, 0, index($currDate, "\/")); $currDate = substr($currDate, index($currDate, "\/")+1); my $oldDay = substr($oldDate, 0, index($oldDate, "\/")); $oldDate = substr($oldDate, index($oldDate, "\/")+1); my $currYear = $currDate; my $oldYear = $oldDate; if ( $currYear > $oldYear ) { return 1; } elsif ( $currMonth > $oldMonth ) { return 1; } elsif ( $currDay > $oldDay ) { return 1; } return 0; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is there an easier way?
by lhoward (Vicar) on May 01, 2001 at 03:25 UTC | |
|
Re: Is there an easier way?
by Beatnik (Parson) on May 01, 2001 at 03:09 UTC | |
by Sherlock (Deacon) on May 01, 2001 at 03:14 UTC | |
|
I'd use something like this...
by cLive ;-) (Prior) on May 01, 2001 at 03:55 UTC | |
by chipmunk (Parson) on May 01, 2001 at 07:28 UTC | |
|
Re: Is there an easier way?
by Starky (Chaplain) on May 01, 2001 at 09:31 UTC | |
|
Re: Is there an easier way?
by ColonelPanic (Friar) on May 01, 2001 at 03:33 UTC | |
by merlyn (Sage) on May 01, 2001 at 03:46 UTC |