[Catalyst] Date fields in mysql

Matt S Trout dbix-class at trout.me.uk
Mon May 7 13:42:46 GMT 2007


On Mon, May 07, 2007 at 01:34:47PM +0200, Dmitri Pissarenko wrote:
> Hello!
> 
> I have a model class, which has one field of "date" type.
> 
> I'm trying to save data in this field using
> 
> my $activity = $c->model('TimeTrackingAppDB::Activity')->create({
>  ...
>  date => $dateAsString,
> });
> 
> where $dateAsString contains a string in this format: "28-5-2007".
> 
> The date is not saved.
> 
> What can I do to save the date (how to convert a string into
> something, which catalyst accepts as a date) ?

This is actually a DBIx::Class question, not a Catalyst one.

But the answer is to use DBIx::Class::InflateColumn::DateTime to auto-inflate
your datetime fields to DateTime objects. Then you can just pass

  date => DateTime->new(year => 2007, month => 5, day => 28)

and DBIx::Class will automatically use the correct formatter for your DB.



More information about the Catalyst mailing list