views:

130

answers:

1

I have a timestamp field (using the timestampable template) that I want formatted differently in the results for only one SELECT query. Is there a way to pass in a date/time format string in the Doctrine_Query::create() method? Or maybe there's a way with ->setParams() or ->setOptions?

I could format the date in the View using Zend_Date, but there's something in the back of my mind that doesn't like that idea.

+2  A: 

Not sure about the formating in the query, but I'd like to answer this part of your question :

I could format the date in the View using Zend_Date, but there's something in the back of my mind that doesn't like that idea.

Formating an output is precisely the job of the View, I think -- and absolutly not the role of the database engine, nor the Model layer.

Moreover, what if you want your application to be internationalized / localized ? Date formats are not the same for every countries / languages ; and that different formating doesn't have its place on the database layer either, I think : it's purely a matter of output -- a matter if View.

Pascal MARTIN
Yep, good point. I'm always thinking in terms of performance in a multi-tiered hardware situation. If you put all the calculation and table join lookup logic on the monster db machine, why not add some date formatting and let the thin web servers work on serving the content. Probably an old skool way of looking at things. :)
Mike
Ergh, I see it exactly the other way arround : I generally consider that PHP scales better than SQL *(i.e. it's either to add a couple of webservers to spread the load than it is to add a couple of SQL servers ^^ )*
Pascal MARTIN
@Mike On my current project, we are using ZF for l8n and i10n. Dates are formatted in the View, while timezone calculations are done inside the queries. I'd go with @Pascal though that you don't want too much logic in the queries. It may be faster (we got a massive data warehouse), but it can also water down separation of concern to an extent where maintaining the app becomes a pain.
Gordon