Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 176647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:54:53+00:00 2026-05-11T13:54:53+00:00

I posted a question earlier today when I’d not zeroed in quite so far

  • 0

I posted a question earlier today when I’d not zeroed in quite so far on the problem. I’ll be able to be more concise here.

I’m running RoR 2.1.2, on Windows, with MySQL. The SQL server’s native time zone is UTC. My local timezone is Pacific (-0800)

I have a model with a :timestamp type column which I can do things like this with:

record = Record.find(:first) record.the_time = Time.now() 

When I do a ‘select * from records’ in the database, the time shown is eight hours in advance of my local time, which is correct, given that the DB is on UTC. (I have verified that it is ‘thinking in utc’ with a simple ‘select now()’ and ‘select utc_timestamp()’)

This is where the trouble begins. If I display the time in a view:

<%= h record.the_time %> 

…then I get back the correct time, displayed in UTC format. If I wrote to the database at 16:40:00 local time, the database showed 00:40:00.

HOWEVER, if I am running a standalone script:

record = Record.find(:first) puts record.the_time 

…then I get back the UTC time that I stored in the database (00:40:00,) but with the local timezone:

Wed Nov 26 00:40:00 (-0800) 2008 

…an eight-hour time warp. Why is it that storing the time translates it correctly, but retrieving it does not? If I compare a stored time from the recent past in the DB and compare it to the current time, the current time is less – telling me this isn’t just a string conversion issue.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:54:53+00:00Added an answer on May 11, 2026 at 1:54 pm

    In the end, it was far easier to do this by storing times as an integer (Time.now().to_i()) and converting them back to a time when I needed to display them (Time.at(the_time_the_database_returned_to_me).) This is hardly the best solution, but it was the only one that worked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had posted another question earlier about deployment with Passenger. That problem turned out
I'm working from a question I posted earlier ( here ), and trying to
I posted a question about this earlier, but I have more information now and
earlier today i posted a question on how to open an image from a
I have posted a question earlier but unfortunately I did not get any useful
I had earlier posted a question, regarding same, but over here i want guidance
I've posted this question in gis.stackexchange earlier but I'm not sure if that was
I posted a question earlier about why django redirect was not working correctly, but
I posted a question earlier about stopping all sounds in a swf. Now, to
I had posted one question earlier jQuery inconsistency in setting readonly attribute in IE-8

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.