On 29 August 2012 07:48, keerthi <
emailtosa...@gmail.com> wrote:
> @colin here i found in console
>
>>> @bio = Biometric.find(36457)
> => #<Biometric id: 36457, rfid: 0, userid: 3, date_time: "2012-08-29
> 09:30:00", checkin_checkout: nil, forget: nil, reason: nil, entered_by: nil,
> created_at: "2012-08-29 09:30:00", updated_at: "2012-08-29 09:30:00",
> RealCheckIn: nil, MACHINENO: nil>
>>> @first = @bio.date_time.to_i
> => 1346232600
>>> @now = Time.now
> => Wed Aug 29 12:13:46 +0530 2012
>>> @time_now = @now.to_i
> => 1346222626
>>> @time_now - @first
> => -9974
>
> @first = @bio.date_time
> => Wed, 29 Aug 2012 09:30:00 UTC +00:00
> with out converting to to_i
>
>>> @now = Time.now
> => Wed Aug 29 12:16:48 +0530 2012
> with out converting to_i
>
> as i found was my date from database is in UTC format and when it comes to
> Time.now its not UTC
>
>
> how can i solve it
First a slight correction. The time in the database is not in UTC
/format/ it is just in UTC. UTC is not a time format it is a time
zone. Assuming that the column type is datetime (look in db/schema.db
to check) it should not be a problem. When you subtract the times it
should allow for the different time zones and give you the correct
difference in seconds, provided that the time in the database is
correct for UTC. If that is not working for you please give an
example of it not working.
If it makes it easier for you to understand what is going on you can
convert Time.now to utc by using Time.now.utc. That will not change
the result when you subtract the utc time in the database of course,
as it is still the same time, just represented in a different time
zone.
Colin