Solved

list dates in previous 4 weeks - oracle sql

Posted on 2011-09-29
2
211 Views
Last Modified: 2012-05-12
i need to write some code to list all the days within the last 4 weeks of the report run date.

If the report was run today (29-sep-2011) i'd want the output to appear as in fig1.
The report would use the current week as week 4, and the 3 weeks prior to that.

If the report was run on 03-Oct-2011 id want the output to appeart as in fig2.

note that the weeks run from Monday - Sunday.

Further more i then want two time stamps to appear next to each day - the times are 10am and 4pm as displayed in fig3. I need the date/ timestamp to be in a usable format (ie not char) so that i can use the output later on to work out time durations.

thanks

sample.xls
0
Comment
Question by:tonMachine100
2 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 36814042
try this...


SELECT d + h / 24 asm_date, TO_CHAR(d + h / 24, 'Day') day_of_week
  FROM (SELECT NEXT_DAY(TRUNC(SYSDATE - 1), 'Sunday') - LEVEL + 1 d
          FROM DUAL
        CONNECT BY LEVEL <= 28),
       (SELECT 10 h FROM DUAL
        UNION ALL
        SELECT 16 FROM DUAL)
ORDER BY 1
0
 

Author Closing Comment

by:tonMachine100
ID: 36814074
works great - thankyou
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Select record with the most recent date 14 67
error in my cursor 5 41
Stored Proc - Rewrite 42 60
Current Month Filter in Visual Studio 10 23
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

831 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