开发者

How to change time part of a datetime value with doctrine?

I need to change the time part of a datetime in a database.

What I got is in the database: '2010-01-01 01:00:00' I need to update this to '2010-01-01 03:00:00' Only thing I have is '03:00:00'

As I'm using doctrine I could iterate through all objects but this would decrease the perfomance. So what I tried w开发者_如何学JAVAas:

$q = Doctrine_Query::create()
                ->update('Something s')
                ->set('start_at', 'DATEADD(DATESUB(start_at,HOUR_SECOND TIME(start_at)), HOUR_SECOND ?)', $doctrine_article->start_time)
                ->set('start_at', 'DATEADD(DATESUB(end_at,HOUR_SECOND TIME(end_at)), HOUR_SECOND ?)', $doctrine_article->end_time)
                ->where('s.some_id = ?',$doctrine_article->id)
                ->andWhere('s.start_at > ?',$current_date)
                ->execute();

(update)

To explain a bit more:

I tried to remove the time part of the current Datetime, so I get '2010-01-01 00:00:00' and then add to this the given time ('03:00:00') so at the end it should be the wanted '2010-01-01 03:00:00'

But this leads to an error (1064 You have an error in your SQL syntax)

Any hints how to solve this error and achieve the described functionality?


It would be easier to use the DATE function to remove the time part. After that, you can use different ways to add the time again:

start_at = DATE(start_at) + INTERVAL 3 HOUR

start_at = DATE(start_at) + INTERVAL 10800 SECOND

start_at = CONCAT(DATE(start_at), ' ', '03:00:00')

and so on.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜