4k9kidz has asked for the wisdom of the Perl Monks concerning the following question:
I am writing a Perl script that will run on a Linux system to which I don't have access, reading records from a SQLserver database. I'm developing the Perl on NT and testing it against our Oracle db using DBI, trying to keep it generic so that the same code will work against both databases. I've loaded 3 records into an Oracle table to test with.
I've run into a stumbling block. One field in the SQLserver table this script will be reading from is of type DATETIME(16). I need to read in that date and compare it to dates from subsequent records, to end up with the earliest date from the table in a variable.
I don't know how to interpret/treat a DATETIME field--what format will it be in when I fetch it with code like this?:
while(my $row = $sth->fetchrow_hashref()) { ($cntct_date) = $row->{"CONTACT_DATE"};
My original approach was to initialize a variable to compare incoming dates to like this (i.e., Jan 1, 3000):
and then compare subsequent dates to it like this using DateManip--but $earliest_date ends up with nothing in it:$earliest_date = "30000101";
$date1 = ParseDate($earliest_date); $date2 = ParseDate($cntct_date); $flag = Date_Cmp($date1,$date2); if ($flag<0) { # date1 is earlier print "$earliest_date was before $cntct_date.\n"; } elsif ($flag==0) { # the two dates are identical print "$earliest_date was THE SAME AS ($cntct_date).\n"; } else { # date2 is earlier, so capture it: print "$cntct_date was earliest--save it.\n"; $earliest_date = $cntct_date; };
Two questions:
1. Is what I'm trying to do (test a script that will run against SQLserver data in DATETIME format using an Oracle table with dates entered in VARCHAR format) even possible?
2. If so, can someone enlighten me as to how I SHOULD be doing this date comparison?
Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with Dates--No Test System!
by tachyon (Chancellor) on Mar 10, 2004 at 19:40 UTC | |
|
Re: Help with Dates--No Test System!
by bean (Monk) on Mar 10, 2004 at 19:43 UTC | |
|
Re: Help with Dates--No Test System!
by Happy-the-monk (Canon) on Mar 10, 2004 at 19:34 UTC | |
by Happy-the-monk (Canon) on Mar 10, 2004 at 20:23 UTC |