Date::Calc should do the job. For your first situation with dates in year/month/day format:
my $string_one = "02/03/08"; # assuming year/month/day
my $string_two = "02/04/02";
my @date_one = split /\//, $string_one;
my @date_two = split /\//, $string_two;
$date_one[0] = 20 . $date_one[0];
$date_two[0] = 20 . $date_two[0];
my $time_one = Date_to_Time(@date_one, 0, 0, 0); # 0s are for hour/min
+/sec
my $time_two = Date_to_Time(@date_two, 0, 0, 0);
if ($time_one > $time_two) {
print "$time_one is newest.\n";
} elsif ($time_one < $time_two) {
print "$time_two is newest.\n";
} else {
print "Same date (to the nearest day).\n";
}
Comparing dates in hour:minuteAM/PM should be simple as well, just split the string for the hour, minute, and AM/PM parts, add 12 to the hours if it contains PM, convert to minutes, and compare.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|