[Dbix-class] Deflating DateTime for searching purposes

Vladimir Melnik v.melnik at uplink.ua
Wed Dec 13 11:47:33 GMT 2017


On Wed, Dec 13, 2017 at 10:42:05PM +1100, Charlie Garrison wrote:
> >I needed to convert `DateTime` objects to an SQL-recognized format
> >(before to give it to the `search()` method), so I'd like to be
> >sure that a `DateTime` object is being deflated according the same
> >algorithm that is being used when I call `update()` or `create()`
> >method.
> Get the formatter from the DBIC storage engine, and format the date
> using that:
>     my $dt_parser = $schema->storage->datetime_parser;
>     my $date_str = $dt_parser->format_datetime($dt);
>     		…->search({date_col => $date_str});
> Even if you switch to a different db type, the storage engine will
> always return a parser which handles parsing/formatting dates in
> correct format.

Oh, thank you so much! I completely forgot about the datetime_parser!

-- 
V.Melnik



More information about the DBIx-Class mailing list