Solved

Difference between 2 dates for holiday report

Posted on 2015-01-12
6
236 Views
Last Modified: 2015-01-13
Guys, I have a report to write and need a little help.

I need to work out the number of days between 2 dates and any holidays that are booked within the 2 dates I need to return 'no of days' there are. Looking below is an example you will see that the column at the far right 'No of Days' shows how many days there are between the 'employment start date' and 'employment end date' where the 'holidays started' and 'holidays ended' are between

ie..

Emp_no   |   employment start date |  employment end date |   holidays started  |  holidays ended   | No of Days

0001        |           01/01/2015              |           12/01/2015           |         02/01/2015    |       08/01/2015      |        7
0001        |           03/01/2015              |           12/01/2015           |         12/01/2015    |       12/01/2015      |        1
0002        |           04/01/2015              |           12/01/2015           |         10/01/2015    |       15/01/2015      |        3
0003        |           02/01/2015              |           12/01/2015           |         18/01/2015    |       22/01/2015      |        0
0004        |           01/01/2015              |           12/01/2015           |         03/01/2015    |       18/01/2015      |        10
0004        |           01/01/2015              |           12/01/2015           |         22/01/2015    |       25/01/2015      |        0


Hope this helps

Regards
0
Comment
Question by:DarrenJackson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 28

Expert Comment

by:Naveen Kumar
ID: 40544276
sorry, I do not get it exactl. How did you get 7 in the output for your first test record ? can you explain pls.
0
 

Author Comment

by:DarrenJackson
ID: 40544282
if you take 'holidays started' less 'holidays ended' it equals 7.

Sorry If I didn't explain
0
 
LVL 28

Assisted Solution

by:Naveen Kumar
Naveen Kumar earned 50 total points
ID: 40544299
so you can just do this right, try this

select trunc(holidays_end - holidays_start ) +1 "No_Of_Days"
from your_table ;
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 35

Assisted Solution

by:Mark Geerlings
Mark Geerlings earned 50 total points
ID: 40544309
Oracle SQL supports calculating the number of days between any two dates, but that doesn't allow for weekends or holidays.

And we may need you to clarify whether by "holiday" you mean the British English defination, which includes what we Americans call "vacation", so they may be different for almost every person, or if this is just those days that Americans call "holidays" (Christmas, Easter, etc.) which are likely to be the same for most people in a particular country.  In either case, you will need a table that clearly indicates which dates should be considered "holidays" for the person being evaluated at the time.  You can do a sub-query from this table to count the number of holidays, then subtract that from the result of the simple Oracle SQL difference between two calendar days.

Do weekend dates also need to be counted differently than "normal" Mon-Fri. days for this report?
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 400 total points
ID: 40544559
SELECT emp_no,
       employment_start_date,
       employment_end_date,
       holidays_started,
       holidays_ended,
       CASE WHEN hdays < 0 THEN 0 ELSE hdays END hdays
  FROM (SELECT t.*,
                 (  LEAST(employment_end_date, holidays_ended)
                  - GREATEST(employment_start_date, holidays_started))
               + 1
                   hdays
          FROM yourtable t)
0
 

Author Comment

by:DarrenJackson
ID: 40546168
Guys thank you all for helping sdstuber has given me exactly what I need.

Thankyou all for a quick respionse
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Via a live example, show how to take different types of Oracle backups using RMAN.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question