Anthony, Joseph wrote:
The string date has a value as 'Jul 18, 2005 7:45:17 PM' and when I directly
store it to an oracle database field datetime, it's storing as
07/18/2005 07:45:17 AM. Not sure why it's converted to AM instead PM.
I don't recognise the format, and anything other than ISO datetimes can
be confusing so I'd use the swiss-army-parser to convert from your
existing format to an ISO datetime: DateTime.pm. Over the past couple of
years we've developed quite a tool suite, and in this case I'd use
DateTime::Format::Strptime to parse the existing code.
use DateTime::Format::Strptime;
my $parser = DateTime::Format::Strptime->new(
pattern => '%b %d, %Y %I:%M:%S %p'
);
$converted_to_iso = $parser->parse_datetime( $original )->datetime;
# or Procedural:
use DateTime::Format::Strptime qw/strptime strftime/;
$converted_to_iso = strftime(
'%Y-%m-%d %H:%M:%S',
strptime(
'%b %d, %Y %I:%M:%S %p',
$original
)
);