[Dbix-class] Deflating a date

Nick Edwards nicke at summerleaze.co.uk
Fri Dec 29 14:48:00 GMT 2006


Hi Tobias,

Thanks for this.

On Thu, 2006-12-28 at 15:23 +0100, Tobias Kremer wrote:
> 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

-- 
Thanks

Nick Edwards <nicke at summerleaze.co.uk>
Information Systems Administrator
Summerleaze RE-Generation Ltd
Tel: 01628 411943





More information about the Dbix-class mailing list