Suppose I have a standard Post.first.created_at
datetime. Can I compare that directly with a datetime in the format 2009-06-03 16:57:45.608000 -04:00
by doing something like:
Post.first.created_at > Time.parse("2009-06-03 16:57:45.608000 -04:00")
Edit: Both fields are datetimes, not dates.
Yes you can compare directly the value of a
created_at
ActiveRecord date/time field with a regularDateTime
object (like the one you can obtain parsing the string you have).In a project i have a Value object that has a created_at datetime object:
The created_at field is defined as:
N.B. if your field is a date and not a datetime, then you need to convert it to a time:
or parse a date:
otherwise you'll get a:
Yes, you can use comparison operators to compare dates e.g.:
But are you trying to compare a date to a datetime?
If that's the case, you'll want to convert the datetime to a date then do the comparison.
I hope this helps.