Get weeks based on start date
Hi ,
i need a query that will determine the weeks based on start date.
if the table consists of:
vDate vAmount
06/25/2007 100
06/27/2007 200
07/04/2007 400
If one enters start date as 6/25/2007 , amounts should be broken out in 7 day increments.
Result should be
week1 300
week2 400
where week1 should be from 6/25/2007 to 07/01/2007,
week2 should be from 07/02/2007 to 07/08/2007
and start date is not always on a Monday or Sunday...
any idea?
thanks in advance
try this...
SQL> with rt as
2 (select 'week'||(trunc(l/7,0)+1) wk_no,to_char(trunc(sysdate)+l,'dd-Mon-yyyy') dt,to_char(trunc(sysdate)+l,'Day') "Day" from
3 (select level-1 l from dual connect by level <= 367) where trunc(sysdate) between trunc(sysdate) and add_months(trunc(sysdate),12)),
4 xx as
5 (select '06/25/2007' vdate, 100 vamount from dual union all
6 select '06/27/2007', 200 from dual union all
7 select '07/04/2007', 400 from dual)
8 select wk_no,sum(vamount) from
9 (select (select wk_no from rt where dt = to_date(vdate,'MM/DD/YYYY')) wk_no,vamount from xx)
10 group by wk_no;
WK_NO SUM(VAMOUNT)
week1 300
week2 400
SQL>
SQL> select 'week'||(trunc(l/7,0)+1) wk_no,to_char(trunc(sysdate)+l,'dd-Mon-yyyy') dt,to_char(trunc(sysdate)+l,'Day') "Day" from
2 (select level-1 l from dual connect by level <= 367) where trunc(sysdate) between trunc(sysdate) and add_months(trunc(sysdate),12);
WK_NO DT Day
week1 25-Jun-2007 Monday
week1 26-Jun-2007 Tuesday
week1 27-Jun-2007 Wednesday
week1 28-Jun-2007 Thursday
week1 29-Jun-2007 Friday
week1 30-Jun-2007 Saturday
week1 01-Jul-2007 Sunday
week2 02-Jul-2007 Monday
week2 03-Jul-2007 Tuesday
week2 04-Jul-2007 Wednesday
week2 05-Jul-2007 Thursday
.
Similar Messages
-
Sums up the last 4 weeks from the start date
Hi all,
Pls tell me how to find the give issue with example
How to write queri in SQL
sums up the last 4 weeks from the start date selected (meaning range of date 1st to 7th) (the 4 weeks should stop on the 31st).
Thanks & Regards<DIV><FONT size=2>
<P><FONT size=2>select</FONT></FONT> tstdate, weeks, (sum*<FONT
color=#0000f0>7</FONT>) as sum<BR>from <SPAN
class=224524108-18042006> </SPAN>(select to_date(<FONT
color=#0000f0>'&date'</FONT>,<FONT color=#0000f0>'dd-mon-rrrr'</FONT>) as
tstdate,<BR><SPAN
class=224524108-18042006>
</SPAN>last_day(to_date(<FONT color=#0000f0>'&date'</FONT>,<FONT
color=#0000f0>'dd-mon-rrrr'</FONT>)) as weeks, <BR><SPAN
class=224524108-18042006>
</SPAN>floor((last_day(to_date(<FONT color=#0000f0>'&date'</FONT>,<FONT
color=#0000f0>'dd-mon-rrrr'</FONT>)) - to_date(<FONT
color=#0000f0>'&date'</FONT>,<FONT color=#0000f0>'dd-mon-rrrr'</FONT>))
/<FONT color=#0000f0>7</FONT>) as sum <BR><SPAN
class=224524108-18042006>
</SPAN>from dual)<FONT size=2></P></FONT></DIV> -
I have a report that takes 2 date parameters ("Start Date" and "End Date"). Get fields back based on that criteria....I want to create a formula field that shows me the "Amount" field data that is equal to the "End Date".
How can I do that?
Thanks in Advance!!Hi shaun,
You can take a running total of the date as
Running total name : datecount
Summary Field to Summarize as : yourdatefield
Type of summary : Nth largest
N is : 1
Evaluate
For Each Record
Reset
Never
Now Create a Formula for ur fileld as
if {Command.Yourdate} = {#datecount} then {Command.fieldname}
I hope this solves your problem
Regards,
Pradeep -
BAPI to create SNP planned order based on start date
Hi,
I am looking for a BAPI to create SNP planned order based on the order start date. There is BAPI BAPI_MOSRVAPS_CREATESNPORDER which can be used to create SNP planned order based on the end date but not based on the start date.
Also would be great if some one can share how do they create SNP Planned orders using BAPI BAPI_MOSRVAPS_CREATESNPORDER in case if GR processing time is defined in the product master and workdays for GR to be respected according to the calendar.
Regards,
VenkatHello Mr.Venkat,
Hope you recognize me.
Please check out the BAdi below.
BAdi - APO_BAPI_BUS10503 (this is the BAdi for ManufactOrderAPS BAPI which contains the SNPorder BAPI)
Method - CHANGE_SAVEMULTIPLE2
In this method parameter IT_ORDER_HEAD contains Order start date input option.
For GR time please check this (not sure if it will help).
Same BAdi/ same method
Parameter IV_PLANNING_MODE_USAGE contains field PLANNING_MODE.
Value 1 for PLANNING_MODE corresponds to "Observance of parameters from the product master".
This may make it respect the GR time in product master
Good luck with the above
Regards,
Ashok -
How to get the current month starting date and ending date by default ?
Hello Creators,
This is my requirement, kindly do the needful, Please dont gimme any links i've no access for other sites, gimme the right solution.
My Requirement :
Creation Date (VBAK-ERDAT) - Select Option. By default, the program should run for the current Month ie between the starting and ending date of the current month when the program is run. Today the date is 18th using sy-datum we can bring the current date by calling it in the initialization event, but the requirement is it should not give me the current date, it should only give me the month starting date and the end date. Kindly help.
Thanks in advance ...DATA: gv_datum LIKE vbak-erdat.
SELECT-OPTIONS: so_date FOR gv_datum.
INITIALIZATION.
CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
EXPORTING
iv_date = sy-datum
IMPORTING
ev_month_begin_date = so_date-low
ev_month_end_date = so_date-high.
so_date-option = 'BT'.
APPEND so_date.
START-OF-SELECTION.
Hope this solves the issue. Don't forget to be generous
Cheers,
Sougata. -
How to get week & quarter for entered date
I need help on below query
1) when i enter date, it should bring previous & further week of that month. As per my requirement my week starts from Saturday to Friday. Lets say that i am entering 24.01.2006, then it should bring week 1 from 7th Jan to 13th Jan 206, 14th Jan to 20th Jan 2006 & so on.
2) Similarly when i enter date as above , i want data coming on quarter basis instead of week..
I will be highly thankfull to you for the help..
Regards
[HASAN]HI
try HR_99S_GET_QUARTER.
type-pools: p99sg.
data: l_week type P99SG_QUARTER.
CALL FUNCTION 'HR_99S_GET_QUARTER'
EXPORTING
IM_DATE = sy-datum
IM_ABKRS =
IM_PERMO =
IMPORTING
EX_QUARTER = l_week.
EX_RETURNCODE =
write:/ l_week-begda.
write:/ l_week-endda.
Message was edited by: Harikishore Sreenivasulu -
Query to get values based on a date range.
11g.
Hi there,
I have a simple requirement(hopefully).
I have a parameter which is basically a count range which when I pass the sql query should fetch the values from a column falling in that range.
My table is item details
Item cost
item1 1
item2 10
item3 20
item4 3
.I have a parameter which I have to pass to this query where items are listed based on the cost.
So I want to select items which cost between 0 -10, 11-20, 21-30 and 31-40
Now I am using Apex to show the count report like
0-10 11- 20 21- 30 31- 40
3 2 0 0
The numbers are hyperlinked and I pass the parameters based on which another report shows the details. So if the user clicks on number 3 in the report. The underlying query would be something like
select * from item_Details where cost between 0 and 10.So I was wondering how do pass the parameter to the sql in the best possible way to get the costs based on the range?
Maybe the parameters should be some code which can be decoded in the SQL?
Any help or suggestions please?
Thanks,
RyanHi,
Try this to pass the parameter in the query...
select * from item_Details where cost between to_number(substr('0-10',0,instr('0-10','-')-1)) and to_number(substr('0-10',instr('0-10','-')+1,length('0-10'));
Regards,
Niha -
Running Aging reports based on Document date in 2007
Hi All,
I have an issue while running the Receivables aging report in the 2007 version. The customer usually runs the reports based on the document date. Document date holds more importance in their case.
However, in the 2007 version, the aging report is totally governed by the posting date. For example, if I change the aging date, the posting date also changes to the aging date and viceversa. If I want to change the aging date to 01/31/09, the posting date u2018Tou2019 automatically changes to 01/31/09 and when we run the report, it will bring in all transactions until the posting date of 01/31/09.
But, the requirement is to leave the posting date as blank and give the document date u2018Tou2019 01/31/09. This will then pull all transactions until the document date of 01/31/09 irrespective of the posting date.
As a result, when you run the balance sheet with the document date of 01/31/09, receivables show a different balance. This discrepancy is due to the fact that AR Receivable aging report forces to keep the Aging date = Posting date.
This was not the case in SAP 2005 version where we were allowed to key in the aging date and the document date to get results based on document date.
This is very critical as they have recently upgraded from 2005 to 2007 and they are unable to reconcile the balances out of Balance sheet and Aging.
Please advise.
Thanks,
PayalHi Jitin,
We tried that as well but no luck. There is still a discrepency between what the aging shows and what the BS shows. When we put the Aging date as 01/31/09 and Document date as 01/3109, the posting date 'To' is automatically filled with 01/31/09, so it basically searches for all transactions with the posting date 01/31/09 and document date 01/31/09. This is not the requirement as we do not want to consider the posting date at all while running the aging.
I also have some screenshots if I can share. I am not sure if I should report this to SAP for further investigation or am I missing something here.
Thanks for your help.
Regards,
Payal
Edited by: Rui Pereira on May 1, 2009 10:48 AM -
How to calculate start date of the week based on week number ?
i need to get week number of the current date and based on that i need to calculate start date falling in the same week for last year.
Eg. today is 31st week of year and 31st july date. so what will be the date on the 31st week of last year. i need the start date of that week.
we can calculate the week number by select to_char(sysdate,'ww') from dual.
DO we have a single line query for that or will it require writing a pl/sql block ?you can try following query
it can be as inline but for more clean look and create it as select with include select
with t as
(select sysdate as dt from dual)
select to_char(prev_year_dt - to_char(prev_year_dt, 'D') + 1, 'DD.MM.YYYY') as start_of_week from (select
-- get day from prev year with the same week number
case
when to_number(to_char(add_months(dt, -12), 'WW')) > to_number(to_char(dt, 'WW')) then
dt - (to_number(to_char(add_months(dt, -12), 'WW')) - to_number(to_char(dt, 'WW'))) * 7
when to_number(to_char(add_months(dt, -12), 'WW')) < to_number(to_char(dt, 'WW')) then
dt + (to_number(to_char(dt, 'WW')) - to_number(to_char(add_months(dt, -12), 'WW'))) * 7
else
add_months(dt, -12)
end as prev_year_dt
from t) t1good luck
Sergii
'Monday' is not first day of week in 100% ;)
Edited by: Galbarad on Jul 30, 2012 11:00 PM -
How to get week starting with sunday date
Hi
I have a date column "start_date", i need to create a report for all the weeks starting from sunday , for eg:
i need to get week dates as :
mm/dd/yy - 01/23/11 , 01/16/11 , 01/09/11 and so on...
Please help
Thanks...Hi,
To find the last Sunday before or equal to start_date:
SELECT TRUNC ( start_date + 1
, 'IW'
) - 1 AS week_start_date
...You can use an expression like this in a GROUP BY clause, also.
This does not depend on you NLS settings. ISO weeks always start on Monday. Your week starts 1 day earlier, so that's why the expression above has the +1 and -1.
(Depending on you NLS settings,
SELECT TRUNC ( start_date
, 'D'
) AS week_start_date
...might do the same thing, but I still rocommend using 'IW'; a few extra keystrokes isn;t much to pay for a guarantee that it will always work.)
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data. -
How can I get the start date and end date of a certain week?
Hello, in my java code, I can get the week ID , using
org.joda.time.base.AbstractDateTime.getWeekOfWeekyear() , for example, this week is the 16th week of this year. And I want to get the start date(date of Monday) and end date(date of Sunday) of the week. Is there any method can supply such date value??thanks1 public Date getCurrentMonday(){
2 Date monday = null;
3 Calendar rightNow = Calendar.getInstance();
4 int day = rightNow.get(Calendar.DAY_OF_WEEK);
5 int distance = 0;
6
7
8 if (day == Calendar.MONDAY)
9 monday = rightNow.getTime();
10 else
11 {
12 distance = day - Calendar.MONDAY;
13 if (distance == -1)
14 distance = 6;
15
16 monday = (Date) (rightNow.getTime());
17 monday.setTime(monday.getTime() - 1000 *60 *60 *24 *(distance));
18 }
19 return monday;
20 } -
How to get back the corresponding date according to 'ISO standard' while giving the week number and year as input. For example, Week=2 and year=2009, then result needed is 5-Jan-2009. Any function to achieve this?
<cffunction name="getStartDateFromWeekNumber" hint="returns start date of the week, given the week number and the year">
<cfargument name="weekno" required="yes">
<cfargument name="year" required="yes">
<cfset var startDate = dateAdd("w",arguments.weekno,createdate(arguments.year,1,1))>
<cfreturn startDate>
</cffunction>
<cfset startDate = getStartDateFromWeekNumber(2,2009)>
<cfset startDate_formatted = dateFormat(startDate, "dd-mmm-yyyy")>
<cfoutput>#startDate_formatted#</cfoutput> -
How to get the week start date from ISO week number
Hi,
I have a table with the following stucture
Year error Week1 week2 week3 ......week53
2012 error1 2 4 2 1
2012 error2 3 0 1 1I was hoping to get something like select year, error, week1||'Week start date which is a monday of that week' , week2||'Week start date,again monday',....week53 from table
Any suggestions please?
Thanks,
SunHi, Sun,
To see when week N started, add 7 * (N - 1) days to the beginning of the year. (By definition, the beginning of the ISO year is the start of week 1 of the ISO year.)
To see when week 22 of the current year started:
SELECT TRUNC (SYSDATE, 'IYYY') + (7 * (22 - 1))
FROM dual
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using.
See the forum FAQ {message:id=9360002} -
Get the starting date and end date of all weeks of a given month and year
hey Guys so far I have this.. but I am having difficulty limiting it by month. I am using Oracle 11 release 1
Select year, week, next_day( to_date( '04-jan-' || year, 'dd-mon-yyyy' ) + (week-2)*7, 'sun' ) as weekStartDate,
next_day( to_date( '04-jan-' || year, 'dd-mon-yyyy' ) + (week-2)*7, 'sun' ) +6 as weekEndDate
from (Select '2012' year, rownum week from all_objects where rownum<=5)
Thanks in advance
Edited by: Aj05 on Jan 12, 2012 7:42 AMFirst you need to define week starting day. If, for example it is Monday:
TRUNC(TRUNC(&dt,'YYYY') -1,'IW')is first Monday of the year. Then:
SELECT TRUNC(TRUNC(&dt,'YYYY') -1,'IW') + (LEVEL - 1) * 7 week_start_date
FROM DUAL
CONNECT BY LEVEL <= 53
/will give start dates of all weeks within &dt year. And:
WITH t AS (
SELECT TRUNC(TRUNC(&dt,'YYYY') -1,'IW') + (LEVEL - 1) * 7 week_start_date
FROM DUAL
CONNECT BY LEVEL <= 53
SELECT week_start_date,
week_start_date + 6 week_end_date
FROM t
WHERE week_start_date > TRUNC(&dt,'MM')
AND week_start_date < ADD_MONTHS(TRUNC(&dt,'MM'),1)
/will give you week start/end dates within &dt year and month. For example:
SQL> DEFINE dt="DATE '2012-03-17'"
SQL> WITH t AS (
2 SELECT TRUNC(TRUNC(&dt,'YYYY') -1,'IW') + (LEVEL - 1) * 7 week_start_date
3 FROM DUAL
4 CONNECT BY LEVEL <= 53
5 )
6 SELECT week_start_date,
7 week_start_date + 6 week_end_date
8 FROM t
9 WHERE week_start_date > TRUNC(&dt,'MM')
10 AND week_start_date < ADD_MONTHS(TRUNC(&dt,'MM'),1)
11 /
old 2: SELECT TRUNC(TRUNC(&dt,'YYYY') -1,'IW') + (LEVEL - 1) * 7 week_start_date
new 2: SELECT TRUNC(TRUNC(DATE '2012-03-17','YYYY') -1,'IW') + (LEVEL - 1) * 7 week_start_date
old 9: WHERE week_start_date > TRUNC(&dt,'MM')
new 9: WHERE week_start_date > TRUNC(DATE '2012-03-17','MM')
old 10: AND week_start_date < ADD_MONTHS(TRUNC(&dt,'MM'),1)
new 10: AND week_start_date < ADD_MONTHS(TRUNC(DATE '2012-03-17','MM'),1)
WEEK_STAR WEEK_END_
05-MAR-12 11-MAR-12
12-MAR-12 18-MAR-12
19-MAR-12 25-MAR-12
26-MAR-12 01-APR-12
SQL> SY. -
How can i get 2nd week starting date and ending date in a month?
please help me to query this.
thanks in advanceHi,
I assume the second week start the next monday after the 1st of the current month. End of week is the next sunday.
If a week start monday, the second week of december start the 5th and ending the 11th :
1 select 8-to_char(to_date('01'||to_char(sysdate,'MMYYYY'),'DDMMYYYY'),'D')+1 first_day2w,
2 15-to_char(to_date('01'||to_char(sysdate,'MMYYYY'),'DDMMYYYY'),'D') last_day2w
3* from dual
SQL> /
FIRST_DAY2W LAST_DAY2W
5 11If we take august, the second week start the 8th to end the 14th
1 select 8-to_char(to_date('01082005','DDMMYYYY'),'D')+1 first_day2w,
2 15-to_char(to_date('01082005','DDMMYYYY'),'D') last_day2w
3* from dual
SQL> /
FIRST_DAY2W LAST_DAY2W
8 14HTH,
Nicolas.
Note that my nls_territory = FRANCE.
if you're in America, first day of week is sunday, and last is saturday :
1* alter session set NLS_TERRITORY='AMERICA'
SQL> /
Session altered.
SQL> ed
Wrote file afiedt.buf
1 select 8-to_char(to_date('01'||to_char(sysdate,'MMYYYY'),'DDMMYYYY'),'D')+1 first_day2w,
2 15-to_char(to_date('01'||to_char(sysdate,'MMYYYY'),'DDMMYYYY'),'D') last_day2w
3* from dual
SQL> /
FIRST_DAY2W LAST_DAY2W
4 10
SQL> Message was edited by:
N. Gasparotto
Maybe you are looking for
-
So I have pages documents and numbers documents that were created on my iPhone5s. When I open them on my iPad (1st gen) it says I need to upgrade to open it, however I can't update the app as it doesn't support it. Is there any way that I can open th
-
Item Cat NLN appears not relevant for picking even it is relevant in 0VLP
Dear Expert, We have an issue in on the behavior of the item category we assigned to the replenishment delivery. The transaction starts from an STO-PO and create a replenishment delivery on the background via VL10B. The replenishment delivery was suc
-
Video playback in Firfox/Safari crashes entire system
My trusty little iBook is now almost 4 years old - after two logic board fixes, it seemed to be running fine. Then one day while repairing permissions using Onyx under Panther (10.3.9), the whole system crashed. Since then I've had to downgrade to th
-
Hi all, I copied the standard work flow for PO release staratagy . In my work flow work flow 2 approvers were there. I am using the 20000027 standard rule for agent assignment . Here My problem is Do i copy task 2 times or 1 time is enough. if user r
-
I have such classes Entity bean @Entity(name = "Actor") @Table(name = "actor") public class Actor extends DomainObject{ @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "actor_id_seq") @Column(columnDefinition = "id")