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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:16:49+00:00 2026-05-22T22:16:49+00:00

In trying to parse a date, I have been racking my brain for hours:

  • 0

In trying to parse a date, I have been racking my brain for hours:

Date.today.to_s
=> "06/07/2011" 

Date.today
=> Tue, 07 Jun 2011 

Date.parse Date.today.to_s
 => Wed, 06 Jul 2011 

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

The default format for to_s is different than the default format for parsing? Why would they do this to me?

Using Rails 3.0.5 with Ruby 1.9.2-p180

UPDATE
So thanks to your answers, I realize that the DATE_FORMATS is a rails thing while Date.format is using the ruby library (correct?). Is there a way then to parse dates/times with the default DATE_FORMAT without using strptime?

  • 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-22T22:16:49+00:00Added an answer on May 22, 2026 at 10:16 pm

    Normally, Date.today.to_s would return “2011-06-07”, but since you set a default date format, it’s using “06/07/2011” instead.

    Date.parse easily recognizes the YYYY-MM-DD format, but when it sees 06/07/2011 it thinks that’s really DD/MM/YYYY (not MM/DD/YYYY as you’re expecting — keep in mind that Date.parse knows nothing about Rails’ default date format you set. The default date format is only for Rails’ outputting of Date.to_s).

    You can force it to parse a MM/DD/YYYY date like this:

    Date.strptime(Date.today.to_s, "%m/%d/%Y")
    # => Tue, 07 Jun 2011
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to parse Java exceptions that appear in a log for
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss]
I have a date of the type August 15, 2009 I'm trying to parse
Hello I have been trying to format this date but it keeps giving me
I'm trying to parse a date/time string using DateTime.ParseExact . It works everywhere, except
I've been trying to convert a date value into a more readable format. To
For the past couple of days, I have been trying to get GWT to
I have a date time as a string, eg. 2010-08-02, I'm trying to convert
I have a problem. I am trying to convert some strings to date, and
I have a Date that has been converted to a String to be passed

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.