Dave, After having a look at:
http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#DATETIME "As a string in either 'YYYY-MM-DD HH:MM:SS' or 'YY-MM-DD HH:MM:SS' format. A ``relaxed'' syntax is allowed--any punctuation character may be used as the delimiter between date parts or time parts. For example, '98-12-31 11:30:45', '98.12.31 11+30+45', '98/12/31 11*30*45', and '[EMAIL PROTECTED]@31 11^30^45' are equivalent." and "As a string with no delimiters in either 'YYYYMMDDHHMMSS' or 'YYMMDDHHMMSS' format, provided that the string makes sense as a date. For example, '19970523091528' and '970523091528' are interpreted as '1997-05-23 09:15:28', but '971122129015' is illegal (it has a nonsensical minute part) and becomes '0000-00-00 00:00:00'." and "As a number in either YYYYMMDDHHMMSS or YYMMDDHHMMSS format, provided that the number makes sense as a date. For example, 19830905132800 and 830905132800 are interpreted as '1983-09-05 13:28:00'." I think being a little more liberal in the excepted DATETIME format is necessary. I think that documentation also says DATETIME can be in the same format as TIMESTAMP(14). Although it's fairly vague on this. DateTime-Format-MySQL-0.01/lib/DateTime/Format/MySQL.pm <patch> --- old.MySQL.pm Thu Mar 20 20:03:58 2003 +++ MySQL.pm Thu Mar 20 20:11:46 2003 @@ -33,7 +33,7 @@ { my ( $self, $date ) = @_; - $date =~ /^(\d+)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)$/ + $date =~ /^(\d{2,4}?) \D?? (\d\d) \D?? (\d\d) \s?? (\d\d) \D?? (\d\d) \D?? (\d\d)$/x or die "Invalid MySQL date: $date\n"; return DateTime->new( year => $1, </patch> DateTime-Format-MySQL-0.01/t/02parse.t <patch> --- old.02parse.t Thu Mar 20 20:05:22 2003 +++ 02parse.t Thu Mar 20 20:06:03 2003 @@ -1,6 +1,6 @@ use strict; -use Test::More tests => 36; +use Test::More tests => 48; use DateTime::Format::MySQL; @@ -15,6 +15,26 @@ { my $dt = $mysql->parse_datetime( '2003-02-15 10:09:08' ); + is( $dt->year, 2003 ); + is( $dt->month, 2 ); + is( $dt->day, 15 ); + is( $dt->hour, 10 ); + is( $dt->minute, 9 ); + is( $dt->second, 8 ); +} + +{ + my $dt = $mysql->parse_datetime( '2003/02/15 10.09.08' ); + is( $dt->year, 2003 ); + is( $dt->month, 2 ); + is( $dt->day, 15 ); + is( $dt->hour, 10 ); + is( $dt->minute, 9 ); + is( $dt->second, 8 ); +} + +{ + my $dt = $mysql->parse_datetime( '20030215100908' ); is( $dt->year, 2003 ); is( $dt->month, 2 ); is( $dt->day, 15 ); </patch> Cheers, -J --
