Skip to content

Instantly share code, notes, and snippets.

@supremebeing7
Created July 13, 2018 05:00
Show Gist options
  • Save supremebeing7/4f25307bfa48cef93d22c54152118e2f to your computer and use it in GitHub Desktop.
Save supremebeing7/4f25307bfa48cef93d22c54152118e2f to your computer and use it in GitHub Desktop.
datetime comparison
001 > User.where('created_at >= ?', '2018-07-12T17:12:37.673+02:00')
User Load (0.5ms) SELECT "users".* FROM "users" WHERE (created_at >= '2018-07-12T17:12:37.673+02:00') LIMIT ? [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<User id: 1, username: "stuff", email: "m@c.com", password_hash: "4dc594e728edf9acd0148eb195e09af68a082ff6", password_salt: "9225fe40b42187ff1fc440b2c32cf2fba67e3be7", created_at: "2018-07-13 04:56:44", updated_at: "2018-07-13 04:56:44">]>
002 > User.where('created_at <= ?', '2018-07-12T17:12:37.673+02:00')
User Load (0.5ms) SELECT "users".* FROM "users" WHERE (created_at <= '2018-07-12T17:12:37.673+02:00') LIMIT ? [["LIMIT", 11]]
=> #<ActiveRecord::Relation []>
003 > user.created_at
=> Fri, 13 Jul 2018 04:56:44 UTC +00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment