Drazen
Drazen

Reputation: 2826

How to get 1.week.ago at 12pm with rails?

I need a week ago at 12pm in milliseconds for a chart.

Now i can do

1.week.ago.to_i * 1000

but this will always return the current time a week ago. How can i get 12pm (noon) ?

Upvotes: 0

Views: 285

Answers (2)

user740584
user740584

Reputation:

1.week.ago.change(hour: 12).to_i * 1000

Actually if you are using Rails 4.1 you could use:

1.week.ago.at_noon.to_i * 1000

according to here, although I'm on 4.0.4 so I haven't tested this

Upvotes: 2

Drazen
Drazen

Reputation: 2826

I did not see this the first time i read the docs.

There is a "at_noon" method.

1.week.ago.at_noon.to_i * 1000

Upvotes: 3

Related Questions