[Dbix-class] Deflating DateTime for searching purposes
Charlie Garrison
garrison at zeta.org.au
Wed Dec 13 11:42:05 GMT 2017
On 13 Dec 2017, at 22:25, Vladimir Melnik 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.
-cng
--
Charlie Garrison <garrison at zeta.org.au>
github.com/cngarrison metacpan.org/author/CNG
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20171213/0b49582a/attachment.htm>
More information about the DBIx-Class
mailing list