[Dbix-class] InflateColumn::DateTime - how to use it?

Adam Herzog adam at herzogdesigns.com
Thu May 10 14:26:50 GMT 2007


On May 10, 2007, at 9:05 AM, RA Jones wrote:
> Adam Herzog wrote:
>> I generally prefer receiving the DateTime object, though, since my  
>> formatting is usually dependent on what I'm doing with the data.  
>> If you're using something like Catalyst, I'd pass the DateTime  
>> object down to the view, and let it decide how to format it.
> Sounds like something for a TT snippet - but how do I call the  
> DateTime object in the template (yes I'm using Cat)?

The DateTime object has a dmy() method which should format the date  
how you want it (dd-mm-yyyy), so displaying it should be pretty  
straightforward.

In your previous code you were doing something similar to this in  
your controller:
while ( my $hits = $rs->next ) {
     push @hits, $hits->date;
}

That should fill @hits with DateTime objects. Assuming you stick  
@hits into your stash, then in your template you can do:

[% FOR hit IN hits; %]
         Date: [% hit.dmy(); %]<br />
[% END; %]

That should display a list of all of the dates, formatted how you  
wanted.

-A



More information about the Dbix-class mailing list