|
Posted by Bob on April 29, 2005, 2:23 am
Please log in for more thread options
Hi all,
I am going to be doing a lot of work with Microsoft SQL Server 2000
using perl and the Win32::ODBC module. Most of this will revolve around
date and time conversions, and as such I was wondering if anyone has
come up with a module(s) for converting between SQL Server DATETIME
strings and perls epoch serial numbers.
I have already checked the Date::Calc and Date::Manip modules from
CPAN, and they do not include such code.
MS SQL DATETIME types (ANSI SQL-92 standard?) should be delimited and
formated as follows, for server INSERTS statements:
'YYYYMMDD'
'YYYY-MM-DDTHH:MM:SS'
'YYYY-MM-DDTHH:MM:SS.xxx'
So for example I would like to go
from: 549929310551181, or Fri Apr 29 09:49:05 2005
to: 20050429, or 2005-04-29T09:49:05, or 2005-04-29T09:49:05.333
and vice-versa, and the time component as optional too, etc.
I am sure one of you guys out there has done this before, right?
Any ideas, suggestions, code, etc in how I should proceed would be
greatly appreciated. Thanks in advance.
|
|
Posted by Thomas Kratz on April 29, 2005, 4:52 pm
Please log in for more thread options
Bob wrote:
> I have already checked the Date::Calc and Date::Manip modules from
> CPAN, and they do not include such code.
>
> MS SQL DATETIME types (ANSI SQL-92 standard?) should be delimited and
> formated as follows, for server INSERTS statements:
>
> 'YYYYMMDD'
> 'YYYY-MM-DDTHH:MM:SS'
> 'YYYY-MM-DDTHH:MM:SS.xxx'
>
> So for example I would like to go
> from: 549929310551181, or Fri Apr 29 09:49:05 2005
> to: 20050429, or 2005-04-29T09:49:05, or 2005-04-29T09:49:05.333
>
> and vice-versa, and the time component as optional too, etc.
One way is POSIX (the strftime function) and Time::Local for the way back.
Both are CORE modules IIRC.
Have a look at the various Time:: modules too. Time::Format looks
promising (haven't used it myself)
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.* |
|
Posted by Jonathan Leffler on April 30, 2005, 9:10 am
Please log in for more thread options
Bob wrote:
> Hi all,
>
> I am going to be doing a lot of work with Microsoft SQL Server 2000
> using perl and the Win32::ODBC module. Most of this will revolve around
> date and time conversions, and as such I was wondering if anyone has
> come up with a module(s) for converting between SQL Server DATETIME
> strings and perls epoch serial numbers.
>
> I have already checked the Date::Calc and Date::Manip modules from
> CPAN, and they do not include such code.
>
> MS SQL DATETIME types (ANSI SQL-92 standard?) should be delimited and
> formated as follows, for server INSERTS statements:
>
> 'YYYYMMDD'
> 'YYYY-MM-DDTHH:MM:SS'
> 'YYYY-MM-DDTHH:MM:SS.xxx'
>
> So for example I would like to go
> from: 549929310551181, or Fri Apr 29 09:49:05 2005
> to: 20050429, or 2005-04-29T09:49:05, or 2005-04-29T09:49:05.333
>
> and vice-versa, and the time component as optional too, etc.
>
>
> I am sure one of you guys out there has done this before, right?
Look at the DateTime::* modules on CPAN.
http://datetime.perl.org/
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2005.01 -- http://dbi.perl.org/
|
| Similar Threads | Posted | | cron manipulation and perl-cgi | September 20, 2004, 5:02 pm |
| perl date manipulation | October 21, 2004, 5:02 pm |
| DateTime - default Timezone ? | August 20, 2004, 2:21 pm |
| ANNOUNCE: DateTime::TimeZone 0.43 | April 13, 2006, 5:22 pm |
| ANNOUNCE: DateTime::TimeZone 0.44 | April 17, 2006, 3:40 pm |
| Using Net::Telnet to connect to Perl server | January 22, 2005, 12:57 am |
| Finding out the time on an FTP server using perl | August 30, 2005, 5:27 am |
| Net:SSH::Perl oddity when logging in to SSH V2 Server | January 16, 2006, 7:03 am |
| net::ssh::Perl connecting to f-secure ssh server | October 10, 2007, 4:07 am |
| Windows Registry manipulation using Unix | April 29, 2005, 11:46 am |
|