Oracle date to days in a week. (plsql)

Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.8.0 - Production
Report Builder 10.1.2.0.2
ORACLE Server Release 10.1.0.4.2
Oracle Procedure Builder 10.1.2.0.2
Oracle ORACLE PL/SQL V10.1.0.4.2 - Production
Oracle CORE    10.1.0.4.0    Production
Oracle Tools Integration Services 10.1.2.0.2
Oracle Tools Common Area 10.1.2.0.2
Oracle Toolkit 2 for Windows 32-bit platforms 10.1.2.0.2
Resource Object Store 10.1.2.0.2
Oracle Help 10.1.2.0.2
Oracle Sqlmgr 10.1.2.0.2
Oracle Query Builder 10.1.2.0.2 - Production
PL/SQL Editor (c) WinMain Software (www.winmain.com), v1.0 (Production)
Oracle ZRC 10.1.2.0.2
Oracle XML Developers Kit 10.1.0.4.2 - Production
Oracle Virtual Graphics System 10.1.2.0.2
Oracle Image 10.1.2.0.2
Oracle Multimedia Widget 10.1.2.0.2
Oracle Tools GUI Utilities 10.1.2.0.2
Select distinct ih.customer_id,patient_name,
        sum(case when to_char(ih.invoice_date,'Mon')=to_char(to_date(:end_date,'DD-MON-YYYY'),'Mon') then id.order_qty else 0 end) curr_month,
from     tab1 ih,
           tab2 id,
           tab4 ip,
           tab3 vp
where id.invoice_number = ih.invoice_number
and id.item_id = vp.product_code
and   id.item_id = ip.item_id
and   ip.item_type in ('P')
and ih.customer_id = 'WAD-EX0128'
and   ih.invoice_date between  to_date('01-JAN-2015','DD-MON-YYYY')  and to_date('31-MAR-2015','DD-MON-YYYY')
and vp.inv_product_type in ('RBC','LRBC','LPHER','PHER','FFP','FP24','CRYO')
group by ih.customer_id,patient_name
I need help in the case statement to distribute qty based on weeks of that month.
This query works fine. But now I need data by weeks, like
customer  id    patient name            Week1                                          Week2
                                              mon   tue   wed  thu    fri  sat   sun     mon   tue   wed  thu    fri  sat   sun
We can just take sample data for 1 month  as start date and 01-jan-2015  and end date as 31-jan-2015. having data for 4 weeks. Help is appreciated. I tried all the queries like
select to_char(sysdate,'IW'), to_char(sysdate,'Dy') from dual;
select to_char(sysdate,'Mon') || ' week' || to_char(sysdate,'W') from dual;
but not getting the data distributed by weeks. Please help me get data based on invoice_date by weeks and days.
Required Data per sample data ( Jan 2015) 1st week.

Being 9i you might try to avoid Dynamic SQL concatenating daily counts to a single month_string (in the past Frank proposed it quite frequently), aligning the strings on weekdays (starting with sunday) and finally using substr to form columns.
select ym,customer_id,patient_name,
       nullif(substr(month_string,1,instr(month_string,',') - 1),'~') sun_1,
       nullif(substr(month_string,instr(month_string,',',1,1) + 1,instr(month_string,',',1,2) - instr(month_string,',',1,1) - 1),'~') mon_1,
       nullif(substr(month_string,instr(month_string,',',1,2) + 1,instr(month_string,',',1,3) - instr(month_string,',',1,2) - 1),'~') tue_1,
       nullif(substr(month_string,instr(month_string,',',1,3) + 1,instr(month_string,',',1,4) - instr(month_string,',',1,3) - 1),'~') wed_1,
       nullif(substr(month_string,instr(month_string,',',1,4) + 1,instr(month_string,',',1,5) - instr(month_string,',',1,4) - 1),'~') thu_1,
       nullif(substr(month_string,instr(month_string,',',1,5) + 1,instr(month_string,',',1,6) - instr(month_string,',',1,5) - 1),'~') fri_1,
       nullif(substr(month_string,instr(month_string,',',1,6) + 1,instr(month_string,',',1,7) - instr(month_string,',',1,6) - 1),'~') sat_1,
       substr(month_string,instr(month_string,',',1,7) + 1,instr(month_string,',',1,8) - instr(month_string,',',1,7) - 1) sun_2,
       substr(month_string,instr(month_string,',',1,8) + 1,instr(month_string,',',1,9) - instr(month_string,',',1,8) - 1) mon_2,
       substr(month_string,instr(month_string,',',1,9) + 1,instr(month_string,',',1,10) - instr(month_string,',',1,9) - 1) tue_2,
       substr(month_string,instr(month_string,',',1,10) + 1,instr(month_string,',',1,11) - instr(month_string,',',1,10) - 1) wed_2,
       substr(month_string,instr(month_string,',',1,11) + 1,instr(month_string,',',1,12) - instr(month_string,',',1,11) - 1) thu_2,
       substr(month_string,instr(month_string,',',1,12) + 1,instr(month_string,',',1,13) - instr(month_string,',',1,12) - 1) fri_2,
       substr(month_string,instr(month_string,',',1,13) + 1,instr(month_string,',',1,14) - instr(month_string,',',1,13) - 1) sat_2,
       substr(month_string,instr(month_string,',',1,14) + 1,instr(month_string,',',1,15) - instr(month_string,',',1,14) - 1) sun_3,
       substr(month_string,instr(month_string,',',1,15) + 1,instr(month_string,',',1,16) - instr(month_string,',',1,15) - 1) mon_3,
       substr(month_string,instr(month_string,',',1,16) + 1,instr(month_string,',',1,17) - instr(month_string,',',1,16) - 1) tue_3,
       substr(month_string,instr(month_string,',',1,17) + 1,instr(month_string,',',1,18) - instr(month_string,',',1,17) - 1) wed_3,
       substr(month_string,instr(month_string,',',1,18) + 1,instr(month_string,',',1,19) - instr(month_string,',',1,18) - 1) thu_3,
       substr(month_string,instr(month_string,',',1,19) + 1,instr(month_string,',',1,20) - instr(month_string,',',1,19) - 1) fri_3,
       substr(month_string,instr(month_string,',',1,20) + 1,instr(month_string,',',1,21) - instr(month_string,',',1,20) - 1) sat_3,
       substr(month_string,instr(month_string,',',1,21) + 1,instr(month_string,',',1,22) - instr(month_string,',',1,21) - 1) sun_4,
       substr(month_string,instr(month_string,',',1,22) + 1,instr(month_string,',',1,23) - instr(month_string,',',1,22) - 1) mon_4,
       substr(month_string,instr(month_string,',',1,23) + 1,instr(month_string,',',1,24) - instr(month_string,',',1,23) - 1) tue_4,
       substr(month_string,instr(month_string,',',1,24) + 1,instr(month_string,',',1,25) - instr(month_string,',',1,24) - 1) wed_4,
       substr(month_string,instr(month_string,',',1,25) + 1,instr(month_string,',',1,26) - instr(month_string,',',1,25) - 1) thu_4,
       substr(month_string,instr(month_string,',',1,26) + 1,instr(month_string,',',1,27) - instr(month_string,',',1,26) - 1) fri_4,
       substr(month_string,instr(month_string,',',1,27) + 1,instr(month_string,',',1,28) - instr(month_string,',',1,27) - 1) sat_4,
       nullif(substr(month_string,instr(month_string,',',1,28) + 1,instr(month_string,',',1,29) - instr(month_string,',',1,28) - 1),'~') sun_5,
       nullif(substr(month_string,instr(month_string,',',1,29) + 1,instr(month_string,',',1,30) - instr(month_string,',',1,29) - 1),'~') mon_5,
       nullif(substr(month_string,instr(month_string,',',1,30) + 1,instr(month_string,',',1,31) - instr(month_string,',',1,30) - 1),'~') tue_5,
       nullif(substr(month_string,instr(month_string,',',1,31) + 1,instr(month_string,',',1,32) - instr(month_string,',',1,31) - 1),'~') wed_5,
       nullif(substr(month_string,instr(month_string,',',1,32) + 1,instr(month_string,',',1,33) - instr(month_string,',',1,32) - 1),'~') thu_5,
       nullif(substr(month_string,instr(month_string,',',1,33) + 1,instr(month_string,',',1,34) - instr(month_string,',',1,33) - 1),'~') fri_5,
       nullif(substr(month_string,instr(month_string,',',1,34) + 1,instr(month_string,',',1,35) - instr(month_string,',',1,34) - 1),'~') sat_5,
       nullif(substr(month_string,instr(month_string,',',1,35) + 1,instr(month_string,',',1,36) - instr(month_string,',',1,35) - 1),'~') sun_6,
       nullif(substr(month_string,instr(month_string,',',1,36) + 1,instr(month_string,',',1,37) - instr(month_string,',',1,36) - 1),'~') mon_6,
       nullif(substr(month_string,instr(month_string,',',1,37) + 1,instr(month_string,',',1,38) - instr(month_string,',',1,37) - 1),'~') tue_6
  from (select ym,customer_id,patient_name,
               case when to_date(ym,'yyyymm') - trunc(to_date(ym,'yyyymm'),'iw') + 1 < 7
                    then rpad('~,',2 * (to_date(ym,'yyyymm') - trunc(to_date(ym,'yyyymm'),'iw') + 1),'~,')
               end||
               days_in_month||
               rpad('~,',
                    2 * (length(replace(case when to_date(ym,'yyyymm') - trunc(to_date(ym,'yyyymm'),'iw') + 1 < 7
                                             then rpad('~,',2 * (to_date(ym,'yyyymm') - trunc(to_date(ym,'yyyymm'),'iw') + 1),'~,')
                                        end||days_in_month,
                         length(case when to_date(ym,'yyyymm') - trunc(to_date(ym,'yyyymm'),'iw') + 1 < 7
                                     then rpad('~,',2 * (to_date(ym,'yyyymm') - trunc(to_date(ym,'yyyymm'),'iw') + 1),'~,')
                                end||days_in_month
                               ) +
                         38
                   '~,'
                   ) month_string
          from (select to_char(trunc(ih.invoice_date,'mm'),'yyyymm') ym,
                       ih.customer_id,
                       patient_name,
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '01' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '02' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '03' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '04' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '05' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '06' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '07' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '08' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '09' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '10' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '11' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '12' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '13' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '14' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '15' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '16' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '17' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '18' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '19' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '20' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '21' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '22' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '23' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '24' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '24' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '25' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '27' then 1 end))||','||
                       to_char(count(case when to_char(ih.invoice_date,'dd') = '28' then 1 end))||','||
                       case when to_char(last_day(trunc(ih.invoice_date,'mm')),'dd') >= '29'
                            then to_char(count(case when to_char(ih.invoice_date,'dd') = '29' then 1 end))
                            else '~'
                       end||','||
                       case when to_char(last_day(trunc(ih.invoice_date,'mm')),'dd') >= '30'
                            then to_char(count(case when to_char(ih.invoice_date,'dd') = '30' then 1 end))
                            else '~'
                       end||','||
                       case when to_char(last_day(trunc(ih.invoice_date,'mm')),'dd') >= '31'
                            then to_char(count(case when to_char(ih.invoice_date,'dd') = '31' then 1 end))
                            else '~'
                       end||',' days_in_month
                  from tab1 ih,
                       tab2 id,
                       tab4 ip,
                       tab3 vp
                 where id.invoice_number = ih.invoice_number
                   and id.item_id = vp.product_code
                   and id.item_id = ip.item_id
                   and ip.item_type in ('P')
                   and ih.customer_id = 'WAD-EX0128'
                   and ih.invoice_date between to_date(:date_from,'DD-MON-YYYY') and to_date(:date_to,'DD-MON-YYYY')
                   and vp.inv_product_type in ('RBC','LRBC','LPHER','PHER','FFP','FP24','CRYO')
                 group by ih.customer_id,patient_name,trunc(ih.invoice_date,'mm')
order by ym,customer_id,patient_name
YM
CUSTOMER_ID
PATIENT_NAME
SUN_1
MON_1
TUE_1
WED_1
THU_1
FRI_1
SAT_1
SUN_2
MON_2
TUE_2
WED_2
THU_2
FRI_2
SAT_2
SUN_3
MON_3
TUE_3
WED_3
THU_3
FRI_3
SAT_3
SUN_4
MON_4
TUE_4
WED_4
THU_4
FRI_4
SAT_4
SUN_5
MON_5
TUE_5
WED_5
THU_5
FRI_5
SAT_5
SUN_6
MON_6
TUE_6
WED_6
201501
WAD-EX0128
ALEXIAN BROTHERS MEDICAL CENTER
9
7
11
11
2
26
14
27
17
21
16
10
14
14
4
50
0
21
13
12
17
26
20
34
34
51
8
1
5
1
41
201502
WAD-EX0128
ALEXIAN BROTHERS MEDICAL CENTER
19
3
27
11
9
0
15
22
32
4
8
16
33
0
54
0
21
26
11
8
13
0
41
11
11
15
18
20
201503
WAD-EX0128
ALEXIAN BROTHERS MEDICAL CENTER
0
5
6
28
0
0
39
0
0

Similar Messages

  • Oracle returning incorrect day of the week

    Hi there,
    I have a table named Performance, which includes a date field named PDATE, some other attributes such as title, etc, and a field named WEEKDAY, which includes the numerical value for the day of the week. Here is an example:
    PER#
    P#
    THEATRE#
    WEEKDAY
    PDATE
    PHOUR
    PMINUTE
    COMMENTS
    1
    1
    1
    1
    02-MAR-10
    19
    30
    Normal evening time
    2
    1
    1
    2
    03-MAR-10
    19
    30
    Normal evening time
    58
    6
    6
    3
    04-MAR-10
    19
    30
    Normal evening time
    5
    1
    1
    4
    05-MAR-10
    19
    30
    Normal evening time
    I went to verify the day of the week in a calendar (in fact I checked more than one) and I noticed that the Weekday value seems incorrect. For instance, the 2nd of March was a Tuesday so I would expect WEEKDAY to say 3 (considering Sunday to be the 1st day of the week, which is the universal norm), or perhaps 2 (considering Monday to be the 1st day of the week).
    First thing that came to mind is, since the WEEKDAY is a number field which has been pre-populated, the person who populated it made a mistake.
    So I went to verify this by running a query that would give me the correct day of the week by extracting it from the PDATE field:
    SELECT DISTINCT pdate, EXTRACT(year from pdate) year,
    to_char(to_date(pdate,'DD/MM/YYYY'),'DY') weekdaycalc, weekday
    FROM ops$yyang00.Performance
    ORDER BY pdate
    And to my astonishment, I got the following table as a return:
    PDATE
    YEAR
    WEEKDAYCALC
    WEEKDAY
    02-MAR-10
    2010
    SUN
    1
    03-MAR-10
    2010
    MON
    2
    04-MAR-10
    2010
    TUE
    3
    05-MAR-10
    2010
    WED
    4
    06-MAR-10
    2010
    THU
    5
    07-MAR-10
    2010
    FRI
    6
    08-MAR-10
    2010
    SAT
    7
    09-MAR-10
    2010
    SUN
    1
    10-MAR-10
    2010
    MON
    2
    As you can see, all of the above WEEKDAYCALC values are incorrect, and seem to match the incorrect values in WEEKDAY.
    I could perhaps understand some weird WEEKDAY numbering if there is some general database setting where I could specify any day of the week to be the first day. However, I can't think of any logical explanation on why Oracle would call a Tuesday Sunday.
    Could someone please advise what I mght be doing wrong? This is driving me insane!
    Thank you in advance for all the help and support.
    Regards,
    P.

    Hi,
    1bded5c7-e555-4306-ac86-45da83dff439 wrote:
    Thanks both Frank and Solomon for the help. I am quite new to Oracle and I feel you folks went the extra mile on the explanation
    Based on your explanations, I changed the formula so the date format would be processed as YY rather than YYY.
    SELECT DISTINCT pdate, EXTRACT(year from pdate) year,   
    to_char(to_date(pdate,'DD/MM/YY'),'DY') weekdaycalc, weekday   
    FROM Performance   
    ORDER BY pdate  
    And I got the correct values now:
    PDATE
    YEAR
    WEEKDAYCALC
    WEEKDAY
    02-MAR-10
    2010
    TUE
    1
    03-MAR-10
    2010
    WED
    2
    04-MAR-10
    2010
    THU
    3
    05-MAR-10
    2010
    FRI
    4
    06-MAR-10
    2010
    SAT
    5
    07-MAR-10
    2010
    SUN
    6
    08-MAR-10
    2010
    MON
    7
    The interesting bit here, is the original WEEKDAY field, which clearly has been created with the same mistake I did (this whole table wasn't created by me). I reckon I spotted a design bug.
    Regards,
    P.
    No; you're still calling TO_DATE on something that is already a DATE, and you're still using an implicit conversion (only now you're using a format such that the current NLS settings don't cause you to get punished.  If your DBA changes the NLS settings next week, then you will have similar errors again.)
    If you want to see what day of the week pdate is, then use:
    TO_CHAR (pdate, 'DY')
    or, to make it NLS-independent:
    TO_CHAR (pdate, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH')
    This is simpler than what you posted, it's more efficient and easier to debug and to maintain, and it also gets the results you want in all cases.
    One more time: TO_DATE, as the name hints, converts something (a VARCHAR2, to be precise) TO a DATE.  If pdate is already a DATE, then what do you need to convert?  You're implicitly converting a DATE to a VARCHAR2, then explicitly converting that VARCHAR2 back to a DATE, and then calling TO_CHAR.  That's 3 function calls (1 of them error prone) where only 1 is needed.
    Also if you ever have to reconcile 2-digit years with 4-digit years (and, again, in this problem you don't) the correct way is to convert the 2-digit year to a 4-digit year, not vice-versa.
    Calling Tuesday the 1st day of the week could make sense in a particular application.

  • Oracle Dates & Working Days

    Hi,
    Is there an Oracle date function that ignores public bank holidays and calculates working days only?

    On the Internet, there is something called 'Google'. It can be used by anyone.
    I just used it for your request and got 569.000 hits.
    Sybrand Bakker
    Senior Oracle DBA

  • Oracle reverse date : inupt (number of the week, number of the date, year)

    Hi experts,
    *I have a date that has been stored in three separated columns in a oracle data base 10g:
    -number of week: for example 30. (range 1-53)
    -number of the day: for example 5. (range 1-7).
    -year : for example 2010.
    *i need to write a SQL code which concate and convert this three columns to one signle date in the format dd/mm/yyyy.
    *This a concrete example:
    -input:
    number of the day: 2, number of the week :23, year 2010.
    -ouput:
    07/06/2010
    Any idea will be welcome
    Best regards.

    Hi,
    Here's one way :
    alter session set nls_date_language = "english";
    alter session set nls_territory = "america";
    WITH date_parts AS (
    select 2010 yr, 23 wk, 2 dy from dual union all
    select 2010 yr, 39 wk, 2 dy from dual
    SELECT next_day(to_date('0101'||yr,'DDMMYYYY')-7, 'SUN') - 1
           + 7*wk
           + dy
           AS dt
    FROM date_parts;You might have to make some adjustments due to your nls settings.

  • Months in a year, days in a week & dates in a month

    Hi guys
    I want 3 sql queries which can giv me the foll
    all months in a year (jan, feb ,mar.....)
    all days in a week (mon, tue, wed....)
    all dates in a month (1,2,3,4,5,.....)
    how can i do this in oracle
    Thanx
    Sushant

    Here you go.
    <code>
    SELECT to_char( add_months(sysdate, r), 'MONTH') AS month
    FROM ( SELECT rownum AS r
    FROM all_objects
    WHERE rownum <= 12)
    SELECT to_char(sysdate+r, 'DAY') AS day, to_char(sysdate+r, 'D') AS day_number
    FROM ( SELECT rownum-1 AS r
    FROM all_objects
    WHERE rownum <= 7)
    SELECT sysdate+r as month_date, to_char( sysdate+r, 'DD') AS month_day
    FROM ( SELECT rownum-to_number(to_char( sysdate, 'DD')) AS r
    FROM all_objects
    WHERE rownum <= to_number(to_char( last_day(sysdate), 'DD')))
    </code>
    Ras malai! APC

  • DATE FOR FIRST DAY OF THE WEEK

    I am new to Oracle and am looking for a procedure that will calculate the first day of the week given today's date.
    Given 1/23/2000 I need to find Sunday 1/21/2000.

    Hi there,
    I don't think there's a built-in Oracle procedure for what you want. However...
    In SQL (at least, Oracle's SQL), you have the function TO_CHAR and TO_DATE that allow you to convert a date to a string and vice-versa. They work pretty much in a similar way, that is :
    TO_<something>( <data_to_convert>, <format> )
    eg.: To have the day of the week for the current date, you can do
    SELECT TO_CHAR( SYSDATE, 'D' ) FROM DUAL;
    Wednesday, January 24th, 2001 would then return 4.
    To have the day of the year, you would do
    TO_CHAR( SYSDATE, 'DDD' )
    Then, to have the day of the year of the first day of the week, you then could subtract the day of the week of your date from the day of the year of your date, and then add one. To be able to do math stuff of char value, you must use TO_NUMBER.
    In one ugly line, you could do this by doing the following :
    select to_date( (to_char(sysdate,'YYYY') &#0124; &#0124; to_char( to_number( to_char(sysdate,'DDD')) - to_number( to_char(sysdate,'D')) + 1)),'YYYYDDD') from dual;
    Eurk.
    Or you could write a function that would return the date of the first day of the week of a specific date, like :
    create or replace
    FUNCTION FDOW (P_DATE DATE) RETURN DATE
    IS
    R_FDOW DATE;
    BEGIN
    R_FDOW := to_date( (to_char(P_DATE,'YYYY') &#0124; &#0124; to_char( to_number( to_char(P_DATE,'DDD')) - to_number( to_char(P_DATE,'D')) + 1)),'YYYYDDD');
    return R_FDOW;
    END;
    (FDOW : First Day Of Week - not really original, I know)
    Then, you can call it wherever you want:
    SELECT FDOW(SYSDATE) FROM DUAL;
    Have fun!
    Frederic Denis

  • Get date of first day of current week

    HI!
    Why does the following method do not return the date of the first day of the week in which the given date lies?
    public static int getFirstDayOfWeek(int year, int month, int date) { 
    GregorianCalendar GregCalendar = (GregorianCalendar)
    new GregorianCalendar(year, month, date).getInstance();
    while(GregCalendar.get(Calendar.DAY_OF_WEEK)!= Calendar.MONDAY) {
    GregCalendar.roll(Calendar.DATE, false);
    return GregCalendar.get(Calendar.DATE);     
    What I want the method to do:
    year = 2003
    month = Calendar.JANUARY
    date = 8
    ==> GregCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY
    ==> GregCalendar.roll(Calendar.DATE, false);
    ==> GregCalendar.get(Calendar.DATE) == 7 (?????????)
    ==> GregCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY
    ==> GregCalendar.roll(Calendar.DATE, false);
    ==> GregCalendar.get(Calendar.DATE) == 6
    ==> GregCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY
    ==> return GregCalendar.get(Calendar.DATE)
    But in reality, it always returns 6 grrrrrrrr
    What is wrong wirh it?
    Yours RB

    public Date getCurrentMonday()
            Date monday = null;
            Calendar rightNow = Calendar.getInstance();
            int day = rightNow.get(Calendar.DAY_OF_WEEK);
            int distance = 0;
            if (day == Calendar.MONDAY)
                monday = rightNow.getTime();
            else
                distance = day - Calendar.MONDAY;
                if (distance == -1)
                    distance = 6;
                monday = (Date) (rightNow.getTime());
                monday.setTime(monday.getTime() - 1000 * 60 * 60 * 24 * (distance));
            return monday;
        }

  • How to get the date of first day of a week for a given date

    Hi gurus
    can any one say me how to get the date of first day(date of Sunday) of a week for a given date in a BW transformations. For example for 02/23/2012 in source i need to get 02/19/2012(Sunday`s date) date in the result. I can get that start date of a week using  BWSO_DATE_GET_FIRST_WEEKDAY function module. But this function module retrieves me the  start date as weeks monday(02/20/2012) date. But i need sundays(02/19/2012) date as the start date. So it would be really great if anyone sends me the solution.
    Thanks
    Rav

    Hi,
    The simplest way would be to subtract 1 from the date date which you are already getting in transformation routine, but instead of doing that subtraction manually which might need bit of errort, you can simply use another FM to subtract 1 from given date.
    RP_CALC_DATE_IN_INTERVAL
    Regards,
    Durgesh.

  • Cannot turn on "Show the day of the week" option in Date & Time

    OS X Lion turns "Show the day of the week" option off each time I open that preference pane and after every reboot. My region in Formats tab of Language & Text preference pane is set to "Russia (Russian)". I've noticed that the problem doesn't appear when region is set to US (I didn't try others). Is there any known workaround, except changing my region preference?

    Me too.
    And I have a workaround, until Фззду fixes it finally:
    1) Go to the ~/Library/Preferences, locate a file named com.apple.menuextra.clock.plist, open it with Plist editor (comes with XCode) or just with TextEdit.
    2) There's DateFormat key in it, change it to "EEE H:mm", save the file.
    3) Now Cmd-I (right click - Get info) on that file in Finder, and check option named "Locked" ("Защита").
    System Preferences' Date & Time pane sets the aforementioned DateFormat to "ccc H:mm" when you tick the "Show the day of the week" option, while in Russian locale. And in English it becomes "EEE H:mm". The problem is that Sys.pref and even SystemUIServer (that shows the menu) processes somehow do not like the former value and erase it. After every relaunch of SystemUIServer (after reboot or being killed) tries to change "EEE" to "ccc" again (which would be cleared to nothing next time), that is why you have to lock the plist file.

  • From where to get "First day of the week" data for all the locales, is it present in CLDR spec 24?

    I am trying to get "First day of the week" data from CLDR spec24 but cannot find where to look for it in the spec. I need this data to calculate numeric value of "LOCAL day of the week".
    This data to implement "c" and "cc" day formats that equals numeric local day of the week.
    e.g if "First day of the week" data for a locale is 2 (Monday) , it means numeric value for local day of the week will be 1 if it is Monday that day, 2 if it is Tuesday that day and likewise.

    Hi
    If you want to week to be started with Sunday then use the following formula:
    TimestampAdd(SQL_TSI_DAY, 1-DAYOFWEEK(Date'@{var_Date}'), Date'@{var_Date}') if it's retail week(starts from Monday) then the follow below:
    TimestampAdd(SQL_TSI_DAY, 1-DAYOFWEEK(Date'@{var_Date}'), Date'@{var_Date}')
    I'm assuming var_Date is the presentation variable for prompt...
    Edited by: Kishore Guggilla on Jan 3, 2011 4:48 PM

  • Date field input help - changing first day of the week

    Hi,
    I need to change the starting day of the week  in a date field value help. I also need to change the days name in this calender.
    Thanks in Advance,
    Dekel.

    I found how to change the first day of the week, through BAdi calendar_definition.
    Can anyone help me locate the day names? (I checked - FM day_names_get dosen't get the names of the UI search help).
    Thanks,
    Dekel.
    Edited by: dekel31 on May 29, 2011 1:17 PM

  • Current date, first day of month, last day of month, current week, current

    Hi All,
    may be the question will sounds basic for your guys, I am connecting via MDX a cognos reportnet on a BW 3.0B..due to loads of limitations on filtering via MDX on 'business date/time functions' , I would need to create in the infoqueries that are my data sources, the following additionnal objects:
    - current date
    - first day of current month
    - last day of current month
    - current week
    - current year
    I do not want prefiltered infoqueiries but object with these single values so that from reportnet I can have something like: OCALDAY between 'first day of current month' and 'last day of curent month'
    Is there standard fonction for this under BW/BEX or if we need to developp functions has nayone some code examples.
    thanks a lot for your great input
    David

    Hi,
    In universe level if you want implement the requirede functions then you have to write custom sql and if you want to implement them in Reporting level then most of the functions are available to you. e.g. Quarter,Month, Year, Current Date....
    Cheers,
    Suresh A.

  • Function module for getting starting day of a week form current data

    Hi ,
    Is there any function module that gives starting day of week when we give a particular date
    eg: today date is 19-12-2007
    if i give this date as input i should get 16-12-2007 because this is starting day of this week .

    Hi,
    Use FM  GET_WEEK_INFO_BASED_ON_DATE
    You will get the first day of the week in export parameter MONDAY
    Lokesh

  • Payment terms - due date on a particular day of the week say friday?

    Experts is it possible in SAP payment terms to configure a term such that due date is on a particular day of the week?
    I want use payment term to determine due date for weekly billing cycle (sunday to saturday) for the invoice to be due on Friday net 27 days from mid point of the week
    eg 1. if a customer is invoiced any day between October 4th to 10th, the due date should be Friday Nov 6th
    eg 2. if a customer is invoiced and day between October 11th to 17th, the due date should be Friday Nov 13th
    Is this possible?
    Thanks in Advance

    You need custom development for this. Using custom development, Substitution in FI or User exit in SD
    I. FI Substitution -
       Create substitution with exit, for field day1 (BSEG-ZBD1T) and baseline date (BSEG-ZFBDT). In exit, determine number of days for required Friday from baseline date you want to use (say document date). This way, due date will be on Friday.
    For determining Friday, use calendar or Ztables.
    II. Invoices created in SD - If you are gerenating invoices in SD, use exit EXIT_SAPLV60B_008. This exit has table ACCIT which also has same fields Day1 and Baseline date. Follow same logic mentioned above.
    I hope this helps.

  • How to get the date for the last day of a week?

    Is there a easy way to get the date for the last day of week?
    eg a week starts on monday and end on sunday
    January 11, 2005 is the start date for the week
    January 17, 2005 is the end date for the week
    or
    say
    February 26, 2003 is the start date for the week
    March 5, 2003 is the end date for the week
    I just need a simple way of figuring that out....
    I figured out how to get the start date for the week but just can't get the latter..
    formatting of the date is not of a concern.. that I know how to do
    thanks in advance

    How about something like the following?
         Calendar someDay = new GregorianCalendar(2005,0,11);//2005 Jan, 11
         //Note above that January is 0, not 1, as counting starts from 0.
          someDay.add(Calendar.DAY_OF_MONTH,6); //add 6 days
         java.util.Date  lastDayOfWeek = someDay.getTime();
         //If someDay was the start of a week, lastDayOfWeek should now be
         //the last day of that week.
         System.out.println(lastDayOfWeek.toString() );

Maybe you are looking for

  • Can you run two Ipods, one older, one newer, on the same version of Itunes?

    I have a second generation Ipod Shuffle, and I have a fourth generation 40gb Ipod. When I installed the Shuffle, I had to upgrade my Itunes. Now it won't recognize my older Ipod at all. I plug it in, and it doesn't do anything. The shuffle works fine

  • How to create a Z BlView for a PCUI application

    Hi can someone tell me the steps to copy and create new Blview for a PCUI application. I'm working with CRM5.0 and need to create a new view for Products Pcui Application. Regards -Rece

  • Problem with H-900

    Hi All, I just purchased new Professional PTZ BRC H-900 from Sony couple month ago to replace old Z-330. Problem is the Pan/Tilt/Zoom cant be sync like Z330 in the preset mode with speed adjustment using RMBR-300 Joystick. Say when I change preset 2

  • IMovie: Event Library Disappears and Projects are Not Editable...

    Was in the middle of editing an iMovie project when it froze. Restarted the application and now there is no list under Project Library, and I can't click on the Event Library. I can see that the video is still there because it plays when I hit the sp

  • Outlook email shows open when email arrives at BlackBerry

    I am using BlackBerry Internet Service (not the Enterprise service) and synching with Outlook.  When I receive an email in Outlook, it comes in regularly and sits in my inbox unopened.  However exactly when the email hits the BB, and I get notified t