Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Checking if a given date falls between 2 other specific dates

by TedPride (Priest)
on Apr 20, 2006 at 17:36 UTC ( [id://544662]=note: print w/replies, xml ) Need Help??


in reply to Checking if a given date falls between 2 other specific dates

Convert the dates to a numerical, fixed-width, greatest significance first format. For instance, if you have Feb 12, 06, you could translate that to 060112, then compare numerically:
use strict; use warnings; my $date1 = dateconvert('Jan 11, 04'); my $date2 = dateconvert('Jan 30, 04'); my $date3 = dateconvert('Feb 10, 04'); print "$date1 <= $date2 <= $date3 ? "; print $date1 <= $date2 && $date2 <= $date3 ? "Yes" : "No"; BEGIN { my @mon = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; my %mon; $mon{$mon[$_]} = $_ for 0..$#mon; sub dateconvert { my $date = $_[0]; my ($mon, $day, $year) = $date =~ m/(\w+) (\d+), (\d+)/; $mon = $mon{$mon}; return sprintf("%02d%02d%02d", $year, $mon, $day); } }
This is easily modified for different formats by changing a couple lines in the function.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://544662]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2024-04-19 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found