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

  • Home
  • SEARCH
  • 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 8466483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:21:23+00:00 2026-06-10T15:21:23+00:00

This question is asking virtually the same as this: Rails date format in form

  • 0

This question is asking virtually the same as this:

  • Rails date format in form field

Except the top answer is not working for me. I’m new to both Ruby and RoR, so I’m not sure what the heck am I doing anyway. Here is what I have so far.

I’ve added the default date and time format in my en.yml:

en:
  date:
    formats:
      default: '%d.%m.%Y'
  time:
    formats:
      default: '%H:%M'

I’ve also added a new initializer with the following code:

Date::DATE_FORMATS[:default] = '%d.%m.%Y'
Time::DATE_FORMATS[:default] = '%H:%M'

When I go to rails console and do Time.now.to_s or Date.today.to_s I get correct results. These also display correctly when fetched from the database and shown on a model index page for example.

However, when I try to create a form with some date and time fields (not datetime!), I get the good old YYYY-MM-DD for dates, and the whole YYYY-MM-DD HH:mm:ss.nnnnnn for time.

What would be the best practise to format these input values correctly? I’d like to avoid changing anything in the view (like it’s done here), and solve this properly – on the application level – if it’s possible at all.

  • 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-06-10T15:21:25+00:00Added an answer on June 10, 2026 at 3:21 pm

    This is what I ended up doing:

    First I’ve defined a custom field in the model:

      attr_accessible :entry_date_formatted
    
      def entry_date_formatted
        self.entry_date.strftime '%d.%m.%Y' unless self.entry_date.nil?
      end
    
      def entry_date_formatted=(value)
        return if value.nil? or value.blank?
        self.entry_date = DateTime.strptime(value, '%d.%m.%Y').to_date
      end
    

    Then I’ve changed my form from entry_date to entry_date_formatted:

    <%= form.text_field :entry_date_formatted, :placeholder => 'Date' %>
    

    Last but not least, I’ve added the relevant fields to my locale file:

    en:
      activerecord:
        attributes:
          time_entry:
            entry_date_formatted: Entry date
            start_time_formatted: Start time
            end_time_formatted: End time
    

    This is probably not the best way, but it serves me well for now.

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

Sidebar

Related Questions

I searched before asking this question. I didn't find an answer probably because I
I am finally asking this question as I have never actually found an answer.
I'm asking this question despite having read similar but not exactly what I want
I am asking this question here as I could not find any conclusive results
I'm asking this question after searching the web for an answer for 2 days.
I beg pardon for not doing homework on this issue and directly asking question
I found this one question asking the same thing , however only the 'new'
This question asking for a phone number format API in Java got me wondering
Similar to this question asking about relatively light-weight data entry / editor application development,
I am asking this question here because it is my understanding that this is

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.