[Dbix-class] format DATE & TIMESTAMP columns
Alex
capfan at gmx.de
Sun Jul 26 09:06:02 GMT 2009
Hi all!
I'm displaying a view on a web page. The view contains a timestamp and a
date field. The database is MySQL 5.0.x.
As raw values from timestamp fields are no eye candy, I decided to use
DBIx::Class::InflateColumn::DateTime, using its default formatter to format
the timestamp. Unfortunately, it formats the date column, too. But as the
date column has no time information, I get something like
"YYYY-MM-DDT00:00:00". I don't want the time information.
Usually, I would format the date and timestamp within the sql statement, but
I wanted to try to format it in the ResultClass. So, how do I do that?
There is a handicap tough. Sure, I could iterate over each item of the
resultset and call some formatting routine for the date field. But I'm too
lazy to do that, because it looks a lot simpler to simply give the resultset
to the template (bzw, using HTML::Template::Compiled) and let the template
handle the output.
Here are some sniplets:
# code:
my $rs = $schema->resultset('View')->search(.);
$template->param(view_loop => $rs);
# template:
<TMPL_LOOP view_loop>
<TMPL_VAR column>
</TMPL_LOOP>
So, any suggestions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090726/3f4d4692/attachment.htm
More information about the DBIx-Class
mailing list