At 1:07 AM -0500 3/29/1999, Ronald J. Kimball wrote: >Eric Albert wrote: >> >> Anyway, I'm stuck with a Sybase database here (blech!). Sybase's datetime >> data type is returned from database calls as a string formatted like this: >> 'Apr 26 1999 4:21:00:000PM' It's always in that format -- "mon dd yyyy >> hh:mm:sssPM" (or AM) if you read the field directly (yes, you can use >> concatenated converts...not pretty, and I'm looking for a Perl solution so >> I can abstract it better). > >Your example string is not consistent with that format... > > 4:21:00:000PM >hh:mm:sssPM > >I'll assume it's a typo in the example string. Laziness again - I didn't write out the complete regex because most displays of date/time formats can generally be assumed to handle such things properly. I'd expect \d\d? for hours.... >> Now, I'm looking to convert this to a formatted string like that of >> strftime, probably using Time::CTime, that looks like this "April 26, 1999 >> 4:21 PM". That's trivial, except in the conversion from 'Apr' to 'April'. > >Because of the way this wrapped, I can't tell whether you want to >preserve the space padding for the hour... It's only the month that I care about...sorry if that wasn't more clear. >> If I don't want to hardcode my months into a hash -- it'd be nice to avoid >> it, just for reasons of laziness and curiousity -- is there any way to do >> the translation? It seems that timelocal and related functions all require >> month *numbers*; does anything allow a name? >> >Well, the months have to be hardcoded somewhere, if not in your code then >in the module you use to do it. Obviously, until we build computers that know English. The only question is whether there is such a creature already.... >For a more general solution, you might be interested in the Date::Parse >module. Yep. That seems to be exactly what I'd like, minus its inability to handle milliseconds starting with ':' instead of '.'. That's easily fixed by changing (?:\.\d+)? to (?:[\.:]\d+)? on line 157, though. Ah, the joy of open source.... :) Thanks for the suggestion, Eric -- Eric Albert ejalbert@cs.stanford.edu http://www.stanford.edu/~ejalbert/ ==== Want to unsubscribe from this list? ==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org