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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:36:23+00:00 2026-05-20T19:36:23+00:00

My Job model has job_date field that is defined in the migration file like

  • 0

My Job model has job_date field that is defined in the migration file like this:

create_table :jobs do |t|
  t.date "job_date", :null => false
  [...]
end

In my development environment (on Windows), when I do:

job = Job.new(:job_date => "17/04/2011")

everything works fine (i.e. the job_date is set properly), while when I do:

job = Job.new(:job_date => "04/17/2011")

job_date is set to nil.

I guess this is because the database (MySQL) expects to get the date in DD/MM/YYYY format.

The problem is that in my production environment, exactly the opposite occurs, i.e.:

job = Job.new(:job_date => "04/17/2011")

sets the ‘job_date` properly, while:

job = Job.new(:job_date => "17/04/2011")

sets it to nil.

How could I solve this inconsistency ?

Is there some way to config the database for specific date format (like DD/MM/YYYY) ?

  • 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-20T19:36:24+00:00Added an answer on May 20, 2026 at 7:36 pm

    It is not a database problem, but I think it is a problem with Date.parse method in Ruby. Infact when you call Job.new it is not saved to database only a new object of the model is created. I beleive Rails call Date.parse method to convert the string into date object and it gives a error for dd/mm/yyyy format in my machine

    Date.parse("17/04/2011")
    => ArgumentError: invalid date
        from /usr/lib/ruby/1.8/date.rb:956:in `new_by_frags'
        from /usr/lib/ruby/1.8/date.rb:1000:in `parse'
        from (irb):3
    

    I think Rails escape this error and gives nil for such values

    job = Job.new(:job_date => "17/04/2011")
    job.job_date
    => nil
    
    job = Job.new(:job_date => "04/17/2011")
    job.job_date
    => Sun, 17 Apr 2011
    

    I guess your production environment’s results are same like my machine and your development machine’s Ruby, Date.parse may be working for the other format.

    If you need to handle only one format(Either dd/mm/yyyy or mm/dd/yyyy), you can use Date.strptime to calculate the date before giving to database

    job_date = Date.strptime("17/04/2011", "%d/%m/%Y") # or "%m/%d/%Y"
    job = Job.new(:job_date => job_date)
    

    This will work both in your production and development environment for one format.

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

Sidebar

Related Questions

This has me seriously stumped. I have a MySQL stored procedure that looks like
I have a job model which has many attributes. I would like to use
I have a dll that has an entity model that does a particular job.
I have an object called human and that object has a field called job.
i have two models: class Category has many :jobs end class Job belongs_to :category
I have a Ruby on Rails app that has a scheduled job I execute
My application has a Job model. Every job in the system has a contact
I have two models Jobs and Questions. A job has many questions and questions
I have a Job model which can have many attachments. The Attachment model has
Using EF Code First I have an model object that has multiple properties that

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.