Gandalf StormCrow
Gandalf StormCrow

Reputation: 26212

Selecting records activerecord

I got this date string :

Mon, 03 Feb 2014 13:51:34 UTC +00:00

How can I select records which have created_at 10 minutes more or less than the date time above?

Question update:

I mean the interval all minutes starting from that time above and going back 10 minutes or 10 minutes in advance, so in that time range

Upvotes: 0

Views: 28

Answers (1)

bjhaid
bjhaid

Reputation: 9782

date = DateTime.parse('Mon, 03 Feb 2014 13:51:34 UTC +00:00')

If Klass is the Active Record Model use range-conditions

Klass.where(created_at: (date - 10.minutes)..(date + 10.minutes))

Upvotes: 3

Related Questions