PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at peppler dot org>
Subject: Re: Differences in convert()ed AM/PM times
Date: Jan 22 2002 4:35PM

David LANDGREN writes:
 > Suppose I have a table with a date column. I might be interested in finding
 > the most recent date. If I write something like this
 > 
 >     my $date = do {
 >         my $r = $db->selectall_arrayref(
 >             'select max(my_date) from t'
 >         );
 >         defined $r and defined $r->[0] ? $r->[0][0] : undef;
 >     };
 >     print $date;
 > 
 > It prints out instead "Jan 15 2002 7:08PM".

Try adding:

$db->func('LONG', '_date_fmt');

before doing the select:

#!/usr/bin/perl -w

use strict;

use DBI;

my $db = DBI->connect('dbi:Sybase:', 'sa', '');
$db->func('LONG', '_date_fmt');

my $date = do {
    my $r = $db->selectall_arrayref('select getdate()');
    defined $r and defined $r->[0] ? $r->[0][0] : undef;
};
print $date, "\n";

Prints:

troll (8:33AM):581 > perl ~/tmp/dbidate.pl 
Jan 22 2002  8:34:14:296AM

Michael
-- 
Michael Peppler - Data Migrations Inc. - http://www.mbay.net/~mpeppler
mpeppler@peppler.org - mpeppler@mbay.net
International Sybase User Group - http://www.isug.com