TAC has asked for the wisdom of the Perl Monks concerning the following question:

Howdy,

I have run into a little problem and I could really use some wisdom to help figure this out. I have a script that uses ADO to execute a stored procedure. It returns a result set that I piece apart and stick into a hash. I have noticed that a date field comes back in a different formats based on the operating system that I run the application. On Win2k it comes back as "mm/dd/yyyy HH:MM:SS" and on NT it comes back as "yy/mm/dd HH:MM:SS". This causes some issues because I need to interrogate the date to perform some calculations to see if an entry in the table has expired. Does anyone have any idea how I can force the date to be in a certain format? I would much rather have Perl or the operating system figure this out so I can port this without having to change code.

Thanks,
Tom

Replies are listed 'Best First'.
Re: ADO and date formats.
by myocom (Deacon) on Aug 22, 2001 at 21:41 UTC

    First, make sure that your results aren't coming from how you have Windows set to display dates (Control Panel/Regional Options). I'm willing to bet that has something to do with your problem.

    Assuming that all checks out ok, though, I'd investigate Date::Manip's ParseDate function to normalize your dates regardless of what format ADO returns it in.

    "One word of warning: if you meet a bunch of Perl programmers on the bus or something, don't look them in the eye. They've been known to try to convert the young into Perl monks." - Frank Willison
Re: ADO and date formats.
by jehuni (Pilgrim) on Aug 23, 2001 at 00:09 UTC

    Also, you should check out Win32::OLE::Variant. It has a Date() function which, according to the documentation, allows you to specify the output format for date strings. (I haven't actually used the function myself, so I can't vouch for how well it works.)

    -jehuni

Re: ADO and date formats.
by MZSanford (Curate) on Aug 22, 2001 at 19:37 UTC
    hmmm ... maybe this (untested, written into browser actually) :
    sub fix_ntdate { my ($date) = shift; if (length($date) == 17) { if ($date =~ m!(\d\d)/(\d\d)/(\d\d) (\d\d):(\d\d):(\d\d)!) { $date = sprintf("%02d/%02d/%4d %02d:%02d:%02d",$2,$3,subst +r((localtime)[5]+1900,0,2).$1,$4,$5,$6); } } return $date; }
    But, watch out for the Y2K like date error problem, and , in looking at the code, just fix all of the errors you will find.
    can't sleep clowns will eat me
    -- MZSanford