How can I manipulate a Sybase datetime string in Perl?

I have a datetime field in a Sybase table, and need to use it in Perl for doing some calculations (differences to make sure I'm picking up the records that are at least 'n' mins apart). Now, if I simply do a select <datetime field>, Sybase returns a human readable field which is no use to me. I was looking at some way to convert this into say, an epoch based time, which will allow me to manipulate them easily in Perl.

I could be wrong but I didn't find an existing function for this in Sybase. The closest I got was datediff, which serves my purpose fine. In fact, I am using that as a workaround for now. The problem with datediff is because of the limitation on integer, it's capped at 68 years. I know my code probably won't be around till that time, but why introduce such a time-based limit on my own?

Is there a way to get around this?



If you're ok with doing it in the client, the Time::ParseDate module should be able to do the work for you.

The DateTime modules have served me well when I need to handle date/time calculations.

Use the DBD::Sybase syb_date_fmt() method to control the format, then use DateTime::Format::Strptime to parse your results and generate DateTime objects. Use the DateTime epoch method to get your epoch time, or better yet do your math using the appropriate DateTime::Duration objects.

If you can't get Sybase and Perl to cooperate to give you a genuine DateTime object or something similar (like Time::Piece), then the way I usually handle such things is to try to convince the database to give me ISO standard date format (YYYY-MM-DDTHH:MI:SS) and convert from there.

Need Your Help

MS Word VBA late binding still causes a reference to be added in 2010 that prevents 2003 running

vba object binding reference ms-word

I have a Word doc with VBA code that is essentially a form that gets routed from originator then through 3 other people via programmatically emailing as an attachment. This requires the document t...

How to debug deadlock with python?

python multithreading debugging deadlock

I am developing a multi-threading application, which is deadlocking.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.