in reply to Need help comparing 4 dates
"When i actually return the dates from oracle and compare 2 dates date_cmp works fine. I'm explaining this because the real issue is that i'm struggling with the concept of how to compare 4 dates..not that __DATA__ doesn't recognize the date formats i added for this sample. "
Returning to Date_Cmp, the doc (perldoc Date::Manip)tells us:
. Compare two dates $date1 = ParseDate($string1); $date2 = ParseDate($string2); $flag = Date_Cmp($date1,$date2); if ($flag<0) { # date1 is earlier } elsif ($flag==0) { # the two dates are identical } else { # date2 is earlier }
Also in the doc, and directly relevant to your desire to compare four dates,
Among other things, Date::Manip allow you to: ... 2. Compare two dates, entered in widely different formats to determine which is earlier
"Compare two dates" is relevant. Comparing two dates is one of the things Date::Manip does; comparing four (without more help from you) is NOT. Since you want to do more, you'll need to change your approach.
For example, you could convert all the date_times to seconds and sort those values, then assign ranks, based on the order in which they sorted (Tedious, but straightforward). Or you could use another capability in Date::Manip, the ability to determines deltas, by comparing each date_date in each row to the date_time of execution, and ranking (ordering) the deltas. Others will undoubtedly suggest other approaches, some of which may be superior to anything here.
ERROR reporting: When executed, your code outputs an error message, "ERROR: Date::Manip unable to determine TimeZone. You didn't tell us that; did you notice it?
Turning again to the doc, you'll find several discussions of TimeZone which may help you turn the code you posted into code that actually compiles. Doing so -- preferably before posting -- is a good way to help assure yourself that Monks inclined to help aren't ( annoyed | turned off ) by the failure to do so.
Update: Likely irrelevant portions stricken. My bad for failing to consider OSen (happened to be on a Win32 machine at the time) and vintage of said machine's modules.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need help comparing 4 dates
by ig (Vicar) on Oct 03, 2010 at 00:49 UTC |