Solved

List of date in previous 4 months - oracle 10 sql

Posted on 2010-11-29
3
614 Views
Last Modified: 2012-05-10
I need a query to list all dates in the last 6 months.
for example eg. we're currently in November,  so if i ran the query today it would list dates back to May. The first date always needs to be a friday so in this instance it will return the 1st Friday before the 1st of May (or return the 1st of may if its a friday), the last day would be the last friday before today (or today if today was friday). I hope this makes sense - i'll include some sample data which will hopefully make my requirments clearer.
sample-dates.xls
0
Comment
Question by:tonMachine100
  • 2
3 Comments
 
LVL 73

Expert Comment

by:sdstuber
ID: 34232446
try this...

select next_day(add_months(trunc(sysdate,'mm'),-6)-7,'Friday') + level - 1 d from dual
connect by next_day(add_months(trunc(sysdate,'mm'),-6)-7,'Friday') + level <= sysdate
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 34232473
oops, forgot the end point condition

change

+ level <= sysdate

to

+ level-1 <= next_day(sysdate-7,'Friday')
0
 

Author Closing Comment

by:tonMachine100
ID: 34237787
Thanks- thats spot on
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

919 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

15 Experts available now in Live!

Get 1:1 Help Now