开发者

Get a "date" type from the DB and add seconds

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.


  1. Convert the value from the DB into a DateTime object in PHP
  2. Use the DateTime::add function to add the seconds
  3. 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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜