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 77989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:55:00+00:00 2026-05-10T20:55:00+00:00

I have config.time_zone in environment.rb set to UTC, and my mySQL server returns the

  • 0

I have config.time_zone in environment.rb set to ‘UTC’, and my mySQL server returns the current time in my local time zone when I issue ‘select now();’ and in utc when I ask for ‘select utc_timestamp;’

I’m running rails 2.1.2, the mysql gem 2.7.3, activerecord gem 2.1.2, and mysql –version returns ‘Ver 14.12 Distrib 5.0.27 for Win32 (ia32)’.

EDIT: My environment.rb is set to UTC and had been since I started the project. A server restart would have picked up no changes.

record = Record.find(:first) puts Time.now # Tue Nov 25 17:40:48 -0800 2008 record.time_column = Time.now record.save  mysql> select * from records; ---------------------  2008-11-26 01:40:48  #note that this is the same time, in UTC.  record = Record.find(:first) puts record.time_column Wed Nov 26 01:40:48 -0800 2008  #NOTE that this is eight hours in advance!   #All I've done is store a date in the database and retrieve it again! 

Any ideas what causes this?

  • 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-10T20:55:01+00:00Added an answer on May 10, 2026 at 8:55 pm

    We had the same issue regarding dates, time zones and MySQL. The latter assumes you provide it with date/time values in the timezone it’s configured with.

    But, since you configured Rails to handle time in UTC, ActiveRecord converts any date/time values in UTC (thus Tue Nov 25 17:40:48 -0800 2008 becomes Wed Nov 26 01:40:48 0000 2008) before using the value in the SQL update/create query it generates and sends to MySQL.

    In pseudo-code

    ('time = %t', Tue Nov 25 17:40:48 -0800 2008) => 'time = '2008-11-26 01:40:48' 

    which is considered as 2008-11-26 01:40:48 -0800 by MySQL.

    Look at your debug log file and you’ll see what I mean. The only way it can properly work (meaning w/o bad surprises) is by setting the same timezone in Rails AND MySQL, this timezone being UTC. This is the configuration we use.

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

Sidebar

Related Questions

I have my checked my environment.rb config.time_zone = 'Prague' Nothing in development.rb regarding time
I have the timezone set. config.time_zone = 'Mountain Time (US & Canada)' Creating a
I have set the time zone in /config/application.rb , and I expect all times
I have the following: config/application.rb config.time.zone = 'Eastern Time (US & Canada)' config.active_record.default_timezone =
In my application I have: config.time_zone = 'Warsaw' A strange issue I have, is
I have a rails app where the time zone is being set in application.rb:
In config/application.rb I have config.time_zone = 'UTC' (without quotes) in the file. I am
By default, Rails' config.time_zone is UTC. So, fields like created_at , updated_at are saved
I have a problem with rails timezones. application.rb config.time_zone = 'Athens' controller @from =
I have a weird problem concerning mysql timezone. In my website config file i

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.