Solved

list dates in previous 4 weeks - oracle sql

Posted on 2011-09-29
2
207 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 73

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
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.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now