Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

list dates in previous 4 weeks - oracle sql

Posted on 2011-09-29
2
Medium Priority
?
230 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
[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
2 Comments
 
LVL 74

Accepted Solution

by:
sdstuber earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

609 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