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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:29:09+00:00 2026-05-27T02:29:09+00:00

I have a start month (3), start year (2004), and I have an end

  • 0

I have a start month (3), start year (2004), and I have an end year (2008). I want to calculate the time in words between the start and end dates. This is what I’m trying and it’s not working..

# first want to piece the start dates together to make an actual date
# I don't have a day, so I'm using 01, couldn't work around not using a day
st = (start_year + "/" + start_month + "/01").to_date
ed = (end_year + "/01/01").to_date

# the above gives me the date March 1st, 2004
# now I go about using the method 
distance_of_time_in_words(st, ed)

..this throws an error, “string can’t me coerced into fixnum”. Anyone seen this error?

  • 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-27T02:29:10+00:00Added an answer on May 27, 2026 at 2:29 am

    You can’t just concatenate strings and numbers in Ruby. You should either convert numbers to strings as mliebelt suggested or use string interpolation like that:

    st = "#{start_year}/#{start_month}/01".to_date
    

    But for your particular case I think there is no need for strings at all. You can do it like that:

    st = Date.new(start_year, start_month, 1)
    ed = Date.new(end_year, 1, 1)
    distance_of_time_in_words(st, ed)
    

    or even like that:

    st = Date.new(start_year, start_month)
    ed = Date.new(end_year)
    distance_of_time_in_words(st, ed)
    

    See Date class docs for more information.

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

Sidebar

Related Questions

Say I have the following 2 dates, a start date and end date: Year-Month-Day
I have a start and end time in a timestamp format. I want to
I have 2 dates. Lets say they look like this. $start = 2010/12/24; $end
I have form with 4 fields namely(start month, start year, end month, end year)
I'm in the U.S., and we usually format dates as "month/day/year". I'm trying to
I have the following query: SELECT location, step, COUNT(*), AVG(foo), YEAR(start), MONTH(start), DAY(start) FROM
I have start date and end date. I need to find out the day
I have start date and end date. I also have particular day i.e. wednesday.
I have a start date and end date field. Both has seperate ajax calender
I have a text file which contains: Cycle code Cycle month Cycle year Event

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.