Hello, all--

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):

$earliest_date = "30000101";
and then compare subsequent dates to it like this using DateManip--but $earliest_date ends up with nothing in it:
$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.


In reply to Help with Dates--No Test System! by 4k9kidz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.