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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:56:25+00:00 2026-05-13T10:56:25+00:00

Is there an easy way to format the display of a DateTime value in

  • 0

Is there an easy way to format the display of a DateTime value in a Rails view?

For example, if I’m doing something like:

<%= text_field :my_object, :start_date %>

and only want to display the Date part of the :start_date (i.e. I want to hide the time part), is there a way to format the :start_date string inside of the view such that it will work for creating new my_object items and updating new my_object items?

Just a clarification:

Doing

<%= text_field 
       :my_object,
       :start_date,
       :value => @my_object.start_date.strftime('%m/%d/%Y') %>

works beautifully when the object already exists (i.e. on item updates), however, when creating a new item, since start_date will initially be nil, the view will throw an error

while evaluating nil.strftime
  • 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-13T10:56:26+00:00Added an answer on May 13, 2026 at 10:56 am

    Some great suggestions here, however in those cases where you really do want your text field date formatted a specific way (say you’re integrating with a javascript date picker), and you’re dealing with nils, I think simply making a minor tweak to your existing method would do the trick:

    :value => (@object.start_date.blank? ? '' : @object.start_date.strftime('%m/%d/%Y'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an easy way in PowerShell to format numbers and the like in
Is there an easy way to create a timestamp, in XML Schema format? datetime.datetime.now()
Is there an easy way to have a text box display a format in
Is there an easy way of getting the datetime of the last change to
I'd like an easy way to display any TimeSpan as an elapsed time without
Is there an easy way to format SQL Server numeric(18,6) data type to format
Is there an easy way to convert a string from csv format into a
Is there an easy way to convert seconds to an mm:ss format (minutes and
Is there an easy way to get the correct format for an iCal DTSTART
%.3f.format(1) returns 1.000 . %.3f.format(4.0/3.0) returns 1.333 . Is there some easy way to

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.