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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:52:18+00:00 2026-06-12T14:52:18+00:00

I am importing data from CSV inside Rails 3.2 and saving it to mongodb

  • 0

I am importing data from CSV inside Rails 3.2 and saving it to mongodb collection and everything works fine except the date field. The imported date format is DD/MM/YYY. Please how can I convert the imported date to YYYY-MM-DD?

Thanks

  • 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-12T14:52:19+00:00Added an answer on June 12, 2026 at 2:52 pm

    You could use date parsing like this:

    Date.strptime('01/02/2003', '%d/%m/%Y').to_s    #=> "2003-02-01"
    
    • Date.strptime creates a Date object from a string in the given format

    • Date#to_s returns it in the ISO 8601 format (i.e. YYYY-MM-DD)

    But it depends on how big your CSV is – this would create a bunch of intermediate Date objects which would be a bit slower than a (slightly ugly) string indexing approach:

    def reformat_date(date)
      "#{date[6..9]}-#{date[3..4]}-#{date[0..1]}"
    end
    
    reformat_date('01/02/2003')     #=> "2003-02-01"
    

    Update

    I was curious so I ran some quick benchmarks – the date parsing method was about 2.7 times slower than the string method (5.289s vs 1.981s for a million conversions, Ruby 1.9.3/Windows). YMMV.

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

Sidebar

Related Questions

I am importing data from csv file, sometimes there are column headers and some
I am importing data from a CSV file into a postgreSQL table. The table
I have some questions about importing data from Excel/CSV File into SQL Server. Let
I'm importing from a CSV and getting data roughly in the format { 'Field1'
So, there have been several posts here about importing and saving data from an
I am importing data from csv file so I used that code <?php $path
I am importing data from a CSV file. One of the fields has an
I am having some difficulty with importing data from a .csv file. I am
I'm importing geocode data to our database from a csv file. I've used the
I'm importing data from a CSV file that comes from excel, but i can't

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.