AnApprentice
AnApprentice

Reputation: 110950

Rails - given a create_at time stamp, I need to know if it is from today or from the past?

I'm working to create an email alert that only sends out if X.created_at is from yesterday or older.

I don't want to alerts going out a day.

Ideas? Thanks

Upvotes: 0

Views: 201

Answers (2)

user973254
user973254

Reputation:

Use ruby's Date.yesterday.to_time.to_i

like

send_email if ob.created_at > Date.yesterday.to_time.to_i

Upvotes: 0

mshiltonj
mshiltonj

Reputation: 316

Anything before midnight last night:

ob.created_at.to_i < Time.now.beginning_of_day.to_i

Anything before 24 hours ago right now:

ob.created_at.to_i < Time.now.to_i - 86400

Upvotes: 2

Related Questions