public function updateAuction($id)
{
$AuctionsTable = Doctrine_Core::getTable('auctions');
$auction = $AuctionsTable->find($id);
$auction->ends_at += 10;
$auction->save();
}
I'm u开发者_如何转开发sing Doctrine to get a record from the database.
I need to increase number of seconds on this records ends_at column, which is a date type.
+=
of course didn't work. What is the quickest way to add, let's say, 10 seconds to ends_at variable? And having handled all the other nuisances that might appear (59 + 10 = 69 seconds).
Perhaps I should use mysql's addtime()
function? But is that implemented with Doctrine? Didn't find anything about addtime()
on doctrine.
- Convert the value from the DB into a DateTime object in PHP
- Use the DateTime::add function to add the seconds
- Put the resulting value back into the DB
try this:
$sec = new Zend_Date($auction->ends_at, Zend_Date::SECOND);
$auction->ends_at = $sec->addSecond(10);
$auction->save();
精彩评论