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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:06:50+00:00 2026-06-01T15:06:50+00:00

I want to create a DateTime instance that lies 20 minutes and 10 seconds

  • 0

I want to create a DateTime instance that lies 20 minutes and 10 seconds in the future.
I tried around with Time and DateTime in irb, but can’t seem to figure out a way that really makes sense. I can only add days to DateTime objects and only add seconds to the Time objects.

Isn’t there a better way than to always convert the time I want to add into seconds?

  • 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-01T15:06:51+00:00Added an answer on June 1, 2026 at 3:06 pm

    A Time is a number of seconds since an epoch whereas a DateTime is a number of days since an epoch which is why adding 1 to a DateTime adds a whole day. You can however add fractions of a day, for example

    d = DateTime.now
    d + Rational(10, 86400)
    

    Will add 10 seconds to d (since there are 86400 seconds in a day).

    If you are using Rails, Active Support adds some helper methods and you can do

    d + 20.minutes + 10.seconds
    

    Which will do the right thing is d is a DateTime or a Time. You can use Active Support on its own, and these days you can pull in just the bits you need. I seem to recall that this stuff is in activesupport/duration. I believe there are a few other gems that offer help with time handling too.

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

Sidebar

Related Questions

I want to create some class that can calculate absolute or relative time period.
I want to create a django app that can upload and display images. However
I want to create a simple class that I can use and encode as
I want to create a Date, Time and DateTime EditorTemplate using MVC3 and Razor.
I want to create two DATETIME variables I can use to check with BETWEEN
I want to create a stored procedure (on SQL Server 2005) that fetches a
I want to create conditional comments in XSLT. But when I use this: <!--
I want create a cache so that when an item doesn't exist, only one
I want to create a MySQL trigger that updates a table everytime one of
I'm working on a python c-extension and want to create an instance of python

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.