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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:18:57+00:00 2026-05-10T23:18:57+00:00

Environment: Rails 2.2.2, Oracle 10g Most of the columns declared date in my ActiveRecord

  • 0

Environment: Rails 2.2.2, Oracle 10g

Most of the columns declared ‘date’ in my ActiveRecord models are exactly that: dates: they don’t care about time at all.

So with a model declared thus:#

class MyDateOnlyModel < ActiveRecord::Migration   def self.up     create_table :my_date_only_model do |t|       t.date :effective_date       t.timestamps     end   end end 

writing a test like this:

test_date = Date.new(2008,12,05) MyDateOnlyModel.create!(:effective_date => test_date) assert_equal test_date, MyDateOnlyModel.find(:first).effective_date 

should pass, shouldn’t it? (Assuming I didn’t mess anything up transcribing the above, of course)

But it doesn’t – not quite. I get this:

<Fri, 05 Dec 2008> expected but was <Fri, 05 Dec 2008 00:00:00 UTC +00:00>. 

So I put a date into the database and got … well what did I get?

puts MyDateOnlyModel.find(:first).eff_date.class 

tells me I actually got a ActiveSupport::TimeWithZone. Which wasn’t what I wanted at all.

Is there a simple way to tell ActiveRecord that some (not all) columns are Dates and only Dates?

UPDATE: more complaining…

Yes, I could use to_date:

assert_equal test_date, MyDateOnlyModel.find(:first).effective_date.to_date 

works fine. But that’s what I’m trying to avoid. I asked AR to make me a date, I want a date back.

And I could add a method to my class, effective_date_as_date – that works too. But surely it’s not impossible to just get a date, dagnabbit.

PRE-ACCEPTANCE UPDATE

Eventually I realised why this was a particular problem with Oracle: there is no distinction between DATE and DATETIME, so ActiveRecord can’t figure out unaided whether a time of zero means midnight (possibly with time zone corrections) or just the date. Bah. Stupid Oracle. So I’m going to have either to go down the plugin route, change my database (tempting, so very tempting) or continue with the to_date/to_time mess I have at present.

  • 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-10T23:18:58+00:00Added an answer on May 10, 2026 at 11:18 pm

    Have you tried casting your attribute to a Date type?

    The API describes to_date as follows:

    Converts self to a Ruby Date object; time portion is discarded

    test_date = Date.new(2008,12,05) MyDateOnlyModel.create!(:effective_date => test_date) assert_equal test_date, MyDateOnlyModel.find(:first).effective_date.to_date 

    Update:

    Enhanced Oracle Adapter

    It looks like this adapter might have a fix for your problem…

    Set the option below and as a result columns with DATE in their name will be emulated as Date (and not as Time which is default for DATE columns in database)

    ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Last night I think I did something that hosed my rails development environment, and
I'm working on a Rails site that connects to an Oracle database, and though
rails-project git:creating-models ❯ rails console Loading development environment (Rails 3.2.1) Couldn't load Wirble: cannot
Environment: Rails 3.0.1 Ruby 1.8.7 MySQL 5.5.16 Community server...Jdk 1.6 gem 'sunspot_rails' gem 'sunspot_solr'
My Environment Rails 3.2.1 ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0] I want to change
My environment: Rails 3.2.x with RVM, Passenger, Apache on Linux (Ubuntu), I am not
My environment is rails 3.1, heroku bamboo stack, delayed_job_active_record, (https://github.com/collectiveidea/delayed_job ) and experimenting with
I have no rails environment but I want to use cruisecontrol.rb as my Continous
I have a rails environment which I set-up with macports. I recently updated macports
I've seen a bunch of articles relating to loading the entire Rails environment for

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.