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

The Archive Base Latest Questions

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

I need a date of birth as a plain text in Ruby on Rails

  • 0

I need a date of birth as a plain text in Ruby on Rails application. So here is the main part of a code I’m using to do it

   if @date_of_birth_as_text.present? and Date.parse(@date_of_birth_as_text).nil?
      errors.add :date_of_birth_as_text, "cannot be parsed"
    end

So it makes everything to a date. Look at it, it’s quite odd

1.9.3p194 :002 > Date.parse("12 12 addd")
 => Sun, 12 Aug 2012 
1.9.3p194 :003 > Date.parse("12 12 october")
 => Fri, 12 Oct 2012 
1.9.3p194 :004 > Date.parse("12 13 october")
 => Sat, 13 Oct 2012 
1.9.3p194 :005 > Date.parse("13 13 october")
 => Sat, 13 Oct 2012 
1.9.3p194 :006 > Date.parse("13 13 2012")
 => Mon, 13 Aug 2012 
1.9.3p194 :007 > Date.parse("13 01 2012")
 => Mon, 13 Aug 2012 
1.9.3p194 :008 > Date.parse("10 01 2012")
 => Fri, 10 Aug 2012 
1.9.3p194 :009 > Date.parse("10 01 2010")
 => Fri, 10 Aug 2012 

I want to change it a little bit. I want a date in format either"MM (any delimeter or not) dd (any delimeter or not) YYYY" or "dd (any delimeter) MM (any delimeter) YYYY" can be parsed. Or something like that, but not “12 12 addd”.

How can I reach it?

P.S I saw gem chronic, please don’t suggest me to it.

  • 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-10T12:21:42+00:00Added an answer on June 10, 2026 at 12:21 pm

    Try using Date.strptime:

    1.9.3-p194 :017 > Date.strptime( '08-29-2012', '%m-%d-%Y' )
     => #<Date: 2012-08-29 ((2456169j,0s,0n),+0s,2299161j)> 
    

    Documentation: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-c-strptime

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

Sidebar

Related Questions

I need the user to select his/her date of birth and I'm using javascript
If I need to search on Date of birth which is stored without the
I need to calculate the age of a customer from their date of birth.
I'm using MS SQL Server 2005 and I need to store date values partially.
I have an entry I need to accept a person's date of birth in.
I need to group by range of years starting from date of birth. This
I need to pull out the records whose First name,lastname and date of birth
I need to validate a primitive date of birth field input in the format
Hey guys I'm I need get a user's date of birth in a form...How
@Column(name=DateOfBirth) private Date dateOfBirth; I specifically need the above code to create a column

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.