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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:56:23+00:00 2026-05-24T23:56:23+00:00

I need to be able add days or hours to a previously created Item.

  • 0

I need to be able add days or hours to a previously created Item.

The system can add or subtract a set number of hours or days based on attributes stored in the db, :operator (add/subtract), :unit_of_time(hours/days), and :number.

I’d like to be able to do something like:

Date.today+2.days

where “+” is the :operator, “2” is the :number, and “days” is the :unit_of_time but I’m unsure of how to get the interpolated string of attributes to become the actual operator “+2.days”. Any ideas?

(I’ve poured through the ruby documentation, but to no avail. Currently, I’m just manually creating of the possible options (4) in nested if/else blocks… yeah it’s gross.)

  • 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-24T23:56:24+00:00Added an answer on May 24, 2026 at 11:56 pm

    You could use eval, e.g.:

    eval("Date.today+2.days")
    

    …and then simply use string interpolation to put in the variables. Note, however, that you should only do this if you can be very certain that the values in your database are always what you want them to be; under no circumstances should users be able to change them, otherwise you’ll have a major security issue which compromises your entire system.

    Using more lengthy methods like the if statement you suggested (or a case statement) require you to write more code, but they are much more secure.

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

Sidebar

Related Questions

I need to be able to add and remove an arbitrary number of points
I need to calculate the number of business days between two dates. How can
I need to be able to add an unkown number of where clauses to
Users need to be able to add a specific type of column to an
I have a table to which i dynamically add rows. The number of days
I need to be able to add a new line to the end of
I'm using Eclipse and I need to be able to add Java libraries (JAR
I'm building a custom module and I need to be able to add an
I need to be able to add 40 markers (places I visited) and show
I need to be able to add all of the user uploaded images to

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.