[Dbix-class] Deflating a date

Tobias Kremer t at funkreich.de
Thu Dec 28 14:23:03 GMT 2006


Hi Nick,

> my $article = $c->model('Pacdb::File::Article')->find_or_create(id =>
> $id);
> $article->set_column(date => $params{date}); # format dd/mm/yyyy
> $article->update;

When setting your date column you have to pass in a DateTime object not a
string like so:

$article->date( DateTime->now );

DateTime::Format::MySQL->format_date expects a DateTime object and will
then make an appropriately formatted MySQL datetime string out of it.
If you need to parse a date stored in a string you could use
DateTime::Format::Strptime (I think) to transform it into a DateTime object
first.

Also check out the handy DBIx::Class::InflateColumn::DateTime component
which saves you from putting inflating/deflating methods into every model.

--Tobias



More information about the Dbix-class mailing list