oracle + working with date/week
Hi
Having som trouble with some SQL in oracle. Is it possible to retreive the date range of a specified week? So if I input week 10 I would get the dates within that week. Or just the start date. It's easy to do the other way around (getting the week from a date). Code:
select to_char('10-AUG-2004', 'iw') from dual; Any idea guys? Any help would be appriciated. |
You're right we do something like this -
Code:
CREATE OR REPLACE FUNCTION week_start ( week_num IN NUMBER) |
Thanks man.....exactly what I was looking for.
|
PL/SQL get a date from a week
You could also try:
create or replace function getDateFromWeek(sYear_in in varchar2,sWeek_in in varchar2,iDay_in in number)return date as dRetDate date; dCondate date; nWeek pls_integer; sWeek_one char(2); begin -- MONDAY: iDay_in==1 -- TUESDAY: iDay_in==2 -- WEDNESDAY: iDay_in==3 -- THURSDAY: iDay_in==4 -- FRIDAY: iDay_in==5 -- SATURDAY: iDay_in==6 -- SUNDAY: iDay_in==7 -- Find the first Monday dCondate := to_date(sYear_in||'0101','YYYYMMDD'); sWeek_one := to_char(dCondate,'IW'); while (sWeek_one!='01') loop dCondate := dCondate + 1; sWeek_one := to_char(dCondate,'IW'); end loop; -- Add the number of weeks nWeek := to_number(sWeek_in); nWeek := nWeek - 1; dCondate := dCondate + (7*nWeek); dRetDate := dCondate; if(iDay_in>1 And iDay_in<8)then dRetDate := dRetDate + iDay_in-1; end if; return dRetDate; end; / |
date range - given weekno and year
Could you please tell me to get weeks date range ,given week no and year?
Thanks |
I got it with the above code.Thanks
|
Not sure whether I understand your question but does this not give you what you want?
Code:
select TRUNC(TRUNC(SYSDATE,'YYYY')+(:WEEK_NUM*7),'IW') FROM DUAL; Quote:
|
Doh - just seen the original post date of this lol.
|
Need add week function in oracle
Hi there,
I need to add weeks in oracle. sysdate+(no_of_weeks*7) will not give correct result. My requirement is like " need to get the same day after n weeks in oracle" If today is MONDAY 28/11/2011 then after 6 weeks It should be MONDAY 09/01/2012... select sysdate+(no_of_weeks*7) will create as issue when no of days in month is 31 or 28... please is there any function exist in oracle which will give " Same day date after n weeks". |
All times are GMT -5. The time now is 09:19 PM. |