Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 637
  • Last Modified:

List of date in previous 4 months - oracle 10 sql

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
tonMachine100
Asked:
tonMachine100
  • 2
1 Solution
 
sdstuberCommented:
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
 
sdstuberCommented:
oops, forgot the end point condition

change

+ level <= sysdate

to

+ level-1 <= next_day(sysdate-7,'Friday')
0
 
tonMachine100Author Commented:
Thanks- thats spot on
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now