30.4k views
1 vote
Using today's date, determine the age (in months) of each book that JustLee sells. Make sure only whole months are displayed; ignore any portions of months. Display the book title, publication date, current date, and age.

User Martimatix
by
7.9k points

1 Answer

3 votes

Final answer:

To determine the age of each book, calculate the difference in months between the publication date and today's date. Use the formula: Age (in months) = (Current Year - Publication Year) * 12 + (Current Month - Publication Month).

Step-by-step explanation:

To determine the age of each book, we need to calculate the difference in months between the publication date and today's date. Let's assume today's date is August 15, 2021, and we have three books with their publication dates:

  • Book 1: Publication date - May 12, 2019
  • Book 2: Publication date - December 1, 2020
  • Book 3: Publication date - February 28, 2021

First, we convert the publication dates and today's date to a common format (day, month, year). Then, we calculate the number of months between the two dates using the formula:

Age (in months) = (Current Year - Publication Year) * 12 + (Current Month - Publication Month)

Let's calculate the age of each book:

  • Book 1: Age = (2021 - 2019) * 12 + (8 - 5) = 24 + 3 = 27 months
  • Book 2: Age = (2021 - 2020) * 12 + (8 - 12) = 12 + (-4) = 8 months
  • Book 3: Age = (2021 - 2021) * 12 + (8 - 2) = 0 + 6 = 6 months

Therefore, the age of each book is 27 months, 8 months, and 6 months respectively.

User Benjamin Seiller
by
8.1k points