Reputation: 1021
I have a question about the format of t.datetime.
When I command in the rails console,
Lesson.find(1781).start_time,
then
the Tue, 03 May 2016 14:00:00 UTC +00:00
is returned.
If I command
Classtime.find_by(start_time: 'Tue, 03 May 2016 14:00:00 UTC +00:00')
, it returns nil.
But if I command
Classtime.find_by(start_time: Lesson.find(1781).start_time)
, it returns
<Classtime id: 4429, start_time: "2016-05-03 14:00:00", created_at: "2016-04-21 15:53:22", updated_at: "2016-04-21 15:53:22">
So I guess, Lesson.find(1781).start_time
is not equal to the return of Lesson.find(1781).start_time
in some sense. How would I be able to know what caused this?
Please share with me!!!
Upvotes: 0
Views: 55
Reputation: 2519
This:
Classtime.find_by(start_time: Lesson.find(1781).start_time)
is the same as:
Classtime.find_by(start_time: '2016-05-03 14:00:00')
which is NOT the same as:
Classtime.find_by(start_time: 'Tue, 03 May 2016 14:00:00 UTC +00:00')
The database knows how to translate the string 2016-05-03 14:00:00
to a date, but not the string Tue, 03 May 2016 14:00:00 UTC +00:00
.
Upvotes: 2