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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:40:15+00:00 2026-05-22T19:40:15+00:00

I have been having this issue for days and couldn’t find any solution for

  • 0

I have been having this issue for days and couldn’t find any solution for this. It seems that I can’t change the format of Date (& DateTime) of a field in a Mongoid Document

class Project
  include Mongoid::Document

  field :deadline, :type => Date
end

Then I can assign Date like this:

p = Project.new
p.deadline = "20-10-2011"

But I can’t assign in other formats:

p.deadline = "20/10/2011"
ArgumentError: invalid date
    from /Users/pww/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/date.rb:956:in `new_by_frags'
    from /Users/pww/.rvm/rubies/ree-1.8.7-2011.03/lib/ruby/1.8/date.rb:1000:in `parse'
    from /Users/pww/.rvm/gems/ree-1.8.7-2011.03@v3/gems/mongoid-2.0.2/lib/mongoid/extensions/date/conversions.rb:18:in `convert_to_time'
    from /Users/pww/.rvm/gems/ree-1.8.7-2011.03@v3/gems/mongoid-2.0.2/lib/mongoid/extensions/time_conversions.rb:6:in `set'
    from /Users/pww/.rvm/gems/ree-1.8.7-2011.03@v3/gems/mongoid-2.0.2/lib/mongoid/field.rb:109:in `set'
    from /Users/pww/.rvm/gems/ree-1.8.7-2011.03@v3/gems/mongoid-2.0.2/lib/mongoid/attributes.rb:182:in `typed_value_for'
    from /Users/pww/.rvm/gems/ree-1.8.7-2011.03@v3/gems/mongoid-2.0.2/lib/mongoid/attributes.rb:96:in `write_attribute'
    from /Users/pww/.rvm/gems/ree-1.8.7-2011.03@v3/gems/mongoid-2.0.2/lib/mongoid/fields.rb:161:in `deadline='
    from (irb):11

The thing is I tried changing the default format of Mongoid Date in several ways including

Date::DATE_FORMATS[:default] = "%d/%m/%Y"

which does work to display the data in that format but not to store the data in the format. I tried with localisation file as follow:

date:
    formats:
      default: "%d/%m/%Y"
      short: "%b %d"
      long: "%B %d %Y"

It doesn’t work either. It’s probably me not know how to get it right but it could be an issue with Mongoid.

I am using:

Mongoid (2.0.2)
Rails (3.0.6)
ree (1.8.7-2011.03)

I am aware of this (https://github.com/mongoid/mongoid/issues/53) which is more a Date timezone issue.

Any help and info with be greatly appreciated.

Thanks.

  • 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. Editorial Team
    Editorial Team
    2026-05-22T19:40:16+00:00Added an answer on May 22, 2026 at 7:40 pm

    If the attribute is defined as date, it expects a valid Date object.
    You should be responsible for parsing the value and assigning a date.

    p = Project.new
    p.deadline = Time.Time.strptime("20/10/2011", "%d/%m/%Y")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been having this memory leak issue for days and I think I have
We have been having this issue pop up sporadically, but now I can reproduce
I have been having this issue with blurry text in WPF. I know that
I have been having this issue in iterating through an array of keys and
This is a really weird problem that I have been having. When I download
This seems like a fairly simple problem to me but I have been having
Ok this is a really annoying bug that I have been having issues with
For a long time I've been having this issue that at a certain time
I have been having this issue for a while now and I cannot seem
I have been having an issue with Visual Studio 2010 that is driving me

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.