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

  • Home
  • SEARCH
  • 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 8938491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:38:16+00:00 2026-06-15T10:38:16+00:00

I am working on a homework problem. For Database SQL programming. Q4. Using today’s

  • 0

I am working on a homework problem. For Database SQL programming.

Q4. Using today’s date (current date), determine the age (in months) of each book that the bookstore sells. Make sure whole months are displayed; ignore any portions of months. Display the book title, publication date, current date, and age. Use column alias for the age column.

Query Results Desired:

TITLE                           PUBDATE                   SYSDATE            AGE                    
BODYBUILD IN 10 MINUTES A DAY  | 21-JAN-01 00:00:00 | 14-NOV-12 13:16:35 | 141  
REVENGE OF MICKEY              | 14-DEC-01 00:00:00 | 14-NOV-12 13:16:35 | 131  
BUILDING A CAR WITH TOOTHPICKS | 18-MAR-02 00:00:00 | 14-NOV-12 13:16:35 | 127    
DATABASE IMPLEMENTATION        | 04-JUN-99 00:00:00 | 14-NOV-12 13:16:35 | 161 
COOKING WITH MUSHROOMS         | 28-FEB-00 00:00:00 | 14-NOV-12 13:16:35 | 152 
HOLY GRAIL OF ORACLE           | 31-DEC-01 00:00:00 | 14-NOV-12 13:16:35 | 130 

14 rows selected 

It’s a table for books and has pub_date, and I’m using sysdate for some interval calculations. The data type for pub_date is DATE.

I’ve worked out the problem, but I’m having trouble getting this rounded time for the pubdate. It’s supposed to be rounded with HH:MM:SS as 00:00:00, but my coding isn’t getting that correct. Here is what I’ve done:

SELECT title, TO_CHAR(ROUND(pubdate), 'DD-MON-YY HH24:MM:SS') AS pubdate,
  TO_CHAR(SYSDATE, 'DD-MON-YY HH24:MM:SS') AS "SYSDATE", 
  ROUND(SYSDATE - TO_DATE(pubdate)) AS age
FROM books;

Something is wroung with my calculation of the age, ROUND(SYSDATE - TO_DATE(pubdate)).

And something is wrong with my coding of the rounded pubdate, TO_CHAR(ROUND(pubdate), 'DD-MON-YY HH24:MM:SS') AS pubdate.

Just wondering how to fix my mistakes on the calculation of age and how to get the correct rounded date like it has it there.

This question refers to Murach’s Oracle SQL, Ch17 How to work with timestamps and intervals.

  • 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-15T10:38:17+00:00Added an answer on June 15, 2026 at 10:38 am

    You can get the number of months between two dates using the months_between function. You can then truncate that to the nearest whole month.

    SELECT title, 
           TO_CHAR(ROUND(pubdate), 'DD-MON-YY HH24:MM:SS') AS pubdate, 
           TO_CHAR(SYSDATE, 'DD-MON-YY HH24:MM:SS') AS "SYSDATE", 
           trunc( months_between( sysdate, pubdate )) AS age 
      FROM books;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a problem for homework in a Java Programming course, and
I have a homework problem here I've been working on; here is the description:
I'm working on a homework problem out of Stalling's Operating Systems: Internals and Design
I'm working on a homework assignment to modify code given by my professor using
Working on basic database design homework and ERD drawing in Visio, and can't wrap
I tried to solve one programming problem(neither my homework nor any of my interview/test,
I'm working on a homework problem and I'm having some difficulties creating a O(n*logn)
I'm working on a homework problem. I'm given the following entities: COMPANY, OPENING, QUALIFICATION,
I am working on a homework assignment for a class. The problem statement says
Earlier today I was working on my homework for my C# class LINK 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.