Note that there are some explanatory texts on larger screens.

plurals
  1. POAutomatically selecting dates from databases as Zend_Date objects
    primarykey
    data
    text
    <p>From what I understand, the best way to deal with dates in the Zend Framework is to select them as a Unix timestamp from the database.</p> <p><a href="http://framework.zend.com/manual/en/zend.date.creation.html#zend.date.creation.database.example-1" rel="nofollow noreferrer">Quick Creation of Dates from Database Date Values</a></p> <pre><code>// SELECT UNIX_TIMESTAMP(my_datetime_column) FROM my_table $date = new Zend_Date($unixtimestamp, Zend_Date::TIMESTAMP); </code></pre> <p>I think it's a pain that there is actually no easy way in Oracle to either select dates as Unix timestamps or in ISO-8601 format - which are the two formats <code>Zend_Date</code> knows best.</p> <p>But I did write a function to select dates as unix timestamps in PL/SQL, so I can actually do this now.</p> <p>Using <code>Zend_Db_Expr</code>, I can now select my dates as Unix timestamps:</p> <pre><code>$select = $db-&gt;select() -&gt;from(array('p' =&gt; 'products'), array( 'product_id', 'product_date' =&gt; new Zend_Db_Expr('toUnixTimestamp(product_date)') ) ); $results = $db-&gt;fetchAll($select); </code></pre> <p>You would use a similar query for any RDMS - most have a timestamp function.</p> <p>I find this anoying because now I have to loop through $results to transform the timestamp to a Zend_Date object manually:</p> <pre><code>foreach($results as $result){ $productDate = new Zend_Date($result['product_date'], Zend_Date::TIMESTAMP); echo $productDate-&gt;toString('dd/MMM/yyyy HH:mm:ss'); } </code></pre> <p>I want my Model to return $results where the timestamps are already transformed to Zend_Date. I don't want to have to write a loop in every data-access function to do this for me.</p> <p>So to get to the point of my actual question:</p> <p><strong><em>Does anyone know of a way with Zend_Db, to set up some sort of post-processing on the result set, thus converting the timestamps to Zend_Date objects automatically?</em></strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload