craphunter
craphunter

Reputation: 981

Doctrine Query <timestamp

I have a colum "datetime", like this: 2012-06-04 15:40:20.

I want to create a query in Doctrine that I get the data of previous time. Less than 2012-06-04 15:40:20. How can I realize that in Doctrine.

Sorry, I just have no clue.

Upvotes: 0

Views: 1772

Answers (2)

Tom
Tom

Reputation: 30698

If I understand your question correctly, I believe the syntax is just:

$datetime = // your timestamp

->where('t.somefield < ?', date('Y-m-d H:i:s', strtotime($datetime))

Upvotes: 1

Gordon Linoff
Gordon Linoff

Reputation: 1270091

I am not familiar with Doctrine, but here is standard SQL to do what you want:

select *
from t
where t.datetime in (select max(datetime)
                     from t
                     where datetime < '2012-06-04 15:40:20'
                    )

If Doctrine supports standard SQL syntax, then something like this would work (you might have to input the date/time constant in a different way).

Upvotes: 0

Related Questions