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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:39:52+00:00 2026-06-03T15:39:52+00:00

In Rails, I see I have a few options to parse a date and

  • 0

In Rails, I see I have a few options to parse a date and a date-time. What is the best practice for parsing dates for the sole purpose of persisting them into the DB via ActiveRecord? And why?

Time.zone.parse(...)
Time.parse(...)
DateTime.parse(...)
  • 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-03T15:39:55+00:00Added an answer on June 3, 2026 at 3:39 pm

    Go with Time.zone.parse if you just want to write into ActiveRecord.

    DateTime should be avoided. If you’re handling dates, you should use Date.parse instead.

    Beyond that, it depends on whether the input comes with timezone information, what the current timezone is set to, and whether you want timezones in your data.

    Time.zone.parse will return an ActiveSupport::TimeWithZone, defaulting to UTC.

    > Time.zone.parse("12:30")
    => Thu, 10 May 2012 12:30:00 UTC +00:00 
    

    Time.parse will return a Time, with a zone if it’s specified in the input, or the local TZ.

    > Time.parse("12:30")
    => 2012-05-09 12:30:00 -0700 
    

    For a more detailed explanation of Ruby time comparisons and precision, read this blog post:

    http://blog.solanolabs.com/rails-time-comparisons-devil-details-etc/

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

Sidebar

Related Questions

I have a ruby on rails application and it would be nice to see
I have a few data values that I need to store on my rails
Just starting to use Ruby on Rails to see what its like. I have
i've started using rails 3 beta3 and I have see that the @template variable
In PHP, I'm trying to steal a page from the Rails playbook (see 'Using
As you can see on rails log: Started GET / for 127.0.0.1 at 2012-05-11
I often see things like this in rails views: <% form_tag some_path do -%>
When using Rails date_select with :prompt => true I see some very strange behavior
[see later answer for more] I think this is just a simple rails question,
Is there an easy way to see the actual SQL generated by a rails

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.