Query to  get  Week number  Pls help

I need to get week number of the current year in the format 2008-W47 ( this is for sysdate
when i try
select to_CHAR(sysdate,'YYYY'||'-IW')
FROM DUAL
i get 2008-47
but in the format 2008-W47
Help
s

SQL> select to_CHAR(sysdate,'YYYY')||'-W'||to_char(sysdate,'IW') from dual
  2  /
TO_CHAR(
2008-W47

Similar Messages

  • Get week number for day from a list of days within a year..

    I am beginning in ORACLE / SQL and wondering how I can use this query to work with a column of Dates that span over a number of years?
    Ideally, I would like to use this script to add a number for the week of the year based on this.
    Then when a new year begins to start over..
    I am referencing an old thread..
    TO_CHAR with dates to get week number issue
    Here is what I have so far:
    I keep getting an error stating "Bind Variable "p_date_beg" is NOT DECLARED"..
    Thanks in advance for any help you can provide.
    DECLARE
    p_date_beg DATE;
    BEGIN
    SELECT RETRIEVAL_DATE
    INTO P_DATE_BEG
    FROM OBS_SELECT_LST12_SPG;
    WITH TAB AS
    (SELECT TO_DATE(TO_CHAR(:p_date_beg,'YYYYMM')||'01','YYYYMMDD') + LEVEL -1 DATE_COL
    FROM DUAL
    CONNECT BY LEVEL <=TO_NUMBER(TO_CHAR(LAST_DAY(:p_date_beg),'DD')))
    SELECT DATE_COL, TO_CHAR(DATE_COL, 'FMDAY') DAY,
    (CASE
    WHEN TO_CHAR(TRUNC(DATE_COL, 'mm'),'FMDAY') = 'SUNDAY'
    THEN TO_NUMBER(TO_CHAR(DATE_COL,'W'))
    ELSE CEIL((TO_CHAR(SYSDATE, 'dd') + 1 - TO_CHAR(NEXT_DAY(TRUNC(SYSDATE, 'mm'), 'SUNDAY'), 'dd'))/7)
    END) WEEK_NOB
    END;

    hi, referring to this link about ISO week, http://www.epochconverter.com/date-and-time/weeknumbers-by-year.php, here is the code:
    /* Formatted on 2012/06/13 06:32 (Formatter Plus v4.8.8) */
    WITH t AS
         (SELECT     MIN (TO_DATE ('20120101', 'rrrrmmdd') + LEVEL - 1)
                                                                       start_date,
                     1 week_th
                FROM DUAL
               WHERE TO_CHAR (  TRUNC (TO_DATE ('20120101', 'rrrrmmdd'), 'mm')
                              + LEVEL
                              - 1,
                              'FMDAY'
                             ) = 'MONDAY'
                 AND (   TO_DATE ('20120101', 'rrrrmmdd') + LEVEL - 1 <
                            TRUNC (NEXT_DAY (TO_DATE ('20120101', 'rrrrmmdd'),
                                             'THU'
                      OR (TO_DATE ('20120101', 'rrrrmmdd') + LEVEL - 1
                             BETWEEN TRUNC (NEXT_DAY (TO_DATE ('20120101',
                                                               'rrrrmmdd'
                                                      'THU'
                                 AND   TRUNC (NEXT_DAY (TO_DATE ('20120101',
                                                                 'rrrrmmdd'
                                                        'THU'
                                     + 7
          CONNECT BY LEVEL < 15),
         v AS
         (SELECT     t.start_date + 7 * (LEVEL - 1) start_date,
                     t.week_th + LEVEL - 1 week_th
                FROM t
          CONNECT BY LEVEL < 53),
         u AS
         (SELECT '20120501' dt
            FROM DUAL
          UNION ALL
          SELECT '20120502'
            FROM DUAL
          UNION ALL
          SELECT '20120503'
            FROM DUAL
          UNION ALL
          SELECT '20120504'
            FROM DUAL
          UNION ALL
          SELECT '20120505'
            FROM DUAL
          UNION ALL
          SELECT '20120506'
            FROM DUAL
          UNION ALL
          SELECT '20120507'
            FROM DUAL
          UNION ALL
          SELECT '20120508'
            FROM DUAL
          UNION ALL
          SELECT '20120509'
            FROM DUAL)
    SELECT *
      FROM u, v
    WHERE TO_DATE (u.dt, 'rrrrmmdd') BETWEEN v.start_date AND (v.start_date + 6);output:
    DT     START_DATE     WEEK_TH
    20120501     30/04/2012     18
    20120502     30/04/2012     18
    20120503     30/04/2012     18
    20120504     30/04/2012     18
    20120505     30/04/2012     18
    20120506     30/04/2012     18
    20120507     07/05/2012     19
    20120508     07/05/2012     19
    20120509     07/05/2012     19

  • Query to get Weekly Report

    Hello,
    I wrote a query to get weekly report, which should start from Sunday to Saturday a typical week. for example the week is 04/03/2011 to 04/09/2011 i run the query on or Job on say on anyday of the week of 04/10/2011, 04.11.2011 etc.. here is my query, but this seems to work from the sysdate to - 7 days which doesn't get the sunday to sat requirement.. can someone please help..
    select uid, psn, TO_char(date_in,'mm/dd/yyyy')
    FROM TEST
    WHERE uid like '%ST%'
    and date_in > trunc(SYSDATE) -7
    ORDER BY date_in ASC;
    Thank you.

    789287 wrote:
    Centiful,
    Thank youvery much for your help. it works now. This should work any day of this week i run will get previous week's data right? 'IW' means ISO calenadar?Yes IW in the TRUNC function means truncate the date passed to the first day of the ISO Week (Monday).
    I made this as a procedure and created a job to run on a weekly basis. once the Job runs and gets the data into text file onto the server, i have to mail the text file to the management automatically through a dbms_scheduler. How can i send an email automatically through a Scheduler? could anyone give me an example please?Instead of creating the text file you could return the data and send it directly in a mail using UTL_MAIL
    Another alternative would be to use DBMS_SCHEDULER to invoke an external executable that could send the mail for you.

  • My iphone 4 missing idont know  ime number pls help me

    sir i want your help my iphone missing i dontknow ime and serial number pls help me

    Help you what?
    You should be able to find your own serial number.  it will not help you find the iphone.
    iPhone: Locating the serial number, IMEI, ICCID, or MEID

  • Calendar to get week number of current month

    Hi All,
    Description: Currently I am working on an application which require to calculate some data for current month from a database where I have the data of all the previous and current month of that year, I can take week number as criteria.
    Help Required: I can find week of month or year using Calendar methods but how to find the first week on the current month only.
    Lets suppose the current month is April so when I use, int weekofmonth = cal.get(cal.WEEK_OF_MONTH);
    it will return me the number of present week however I want to get what would be the week number at the start of the month (April).
    Hope I am able to describe my query properly.
    Thanks in advance.
    Amit

    / ====================================================
    Method: Get the desired Date format for the date
    Developed By: Sandip Waghole [29-Jan-2010]
    ==================================================== /
    public String getWeekNo(String strDate)
    // input Date Format : M/dd/yyyy
    int weekNo=0,i=0;
    String strWeekNo=null;
    int noOfDaysInTheYear=365;
    int WEEK_STARTS_ON = 1; // Define the day on which week starts Sunday/Monday 1:Sunday 2:Monday
    int firstDayNoInFirstWeekOfPresentYear=0; // Inititalize teh day on which week is starting in present year
    int firstDayOfPresentYear=0; // Inititlize the 1st day of the present year whether Sunday/Monday/.....
    int[] monthDaysArray = {31,28,31,30,31,30,31,31,30,31,30,31}; // Define array of the days as per months
    int todaysDayNoInPresentYear=0;
    int daysLateByFirstWeekStartedAfterYearStarted=0;
    int intTemp=0;
    //strDate="08/24/2000"; // For test purpose
    StringTokenizer strDateTok = new StringTokenizer(strDate, "/ ");
    int month = Integer.parseInt(strDateTok.nextToken());
    int day= Integer.parseInt(strDateTok.nextToken());
    int year = Integer.parseInt(strDateTok.nextToken());
    GregorianCalendar cal = new GregorianCalendar();
    // Check if present year is leap year
    boolean boolIsLeapYear = cal.isLeapYear(year);
    // If it is boolean year then add 1 to total days in the year & add one more day to february
    if(boolIsLeapYear)
    noOfDaysInTheYear=noOfDaysInTheYear+1;
    monthDaysArray[1]=monthDaysArray[1]1;
    // Find the 1st day of this year
    Calendar calObj = new GregorianCalendar(year, Calendar.JANUARY, 1);
    firstDayOfPresentYear = calObj.get(Calendar.DAY_OF_WEEK);
    int intRemoveNoOfDaysFromWeek=0;
    // # Find the day no of prsent day
    for(i=0;i<month;i+) // get no of days till present year
    intTemp = intTemp monthDaysArray;
    todaysDayNoInPresentYear = intTemp - (monthDaysArray[month-1]-day);
    if(firstDayOfPresentYear==6 || firstDayOfPresentYear==7) // If first Day is Friday or Saturday then it is week
    // Identify the the day no on which 1st week of present year is starting
    firstDayNoInFirstWeekOfPresentYear = 7 - firstDayOfPresentYear WEEK_STARTS_ON 1;
    // Find delay in the 1st week start after r=the year start
    daysLateByFirstWeekStartedAfterYearStarted = firstDayNoInFirstWeekOfPresentYear - 1;
    // Now week is starting from Sunday
    weekNo = (Integer)((todaysDayNoInPresentYear-daysLateByFirstWeekStartedAfterYearStarted)/7);
    // Find the day no of today
    intTemp = (todaysDayNoInPresentYear-daysLateByFirstWeekStartedAfterYearStarted) % 7;
    if(intTemp > 0)
    weekNo=weekNo+1;
    else
    weekNo=weekNo;
    else
    // 1st week is starting on 1st Of January
    firstDayNoInFirstWeekOfPresentYear=firstDayOfPresentYear;
    // Remove no. of days from the 1st week as week is starting from odd Sunday/Monday/Tuesday/Wednesday/Thursday
    intRemoveNoOfDaysFromWeek = 7-firstDayOfPresentYear 1; // 1 added as include start day also
    // So one week will be added in no. of weeks
    weekNo = (Integer)((todaysDayNoInPresentYear-intRemoveNoOfDaysFromWeek)/7);
    // Find the day no of today
    intTemp = (todaysDayNoInPresentYear-intRemoveNoOfDaysFromWeek) % 7;
    weekNo = weekNo +1; // As 1st weeks days are reduced from the todays day no in the year
    if(intTemp > 0)
    weekNo=weekNo+1;
    else
    weekNo=weekNo;
    // Remove the no. of days from the week 1
    strWeekNo=Integer.toString(weekNo);
    return strWeekNo;
    // Any issues please mail on [email protected] or [email protected]

  • QUERY CLARIFICATION RQD :  gurus, experts pls help

    Hai,
    I am facing problem in performance of the query. sample scenario i have created here pls help me to solve
    **VEH_MAIN* TABLE (MASTER TABLE)*
    CREATE TABLE VEH_MAIN
       (     VIP_MOT_IND VARCHAR2(10 BYTE),
         VIP_IND NUMBER(10,0)
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT01',1);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT02',5);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('M0T03',1);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT01',2);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT02',6);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT01',3);
    Insert into VEH_MAIN (VIP_MOT_IND,VIP_IND) values ('MOT01',4);
    **VEH_ENGINE_SUB* (table for engine subclass)*
      CREATE TABLE VEH_ENG_SUB
       (     ENG_SUBCLASS VARCHAR2(50 BYTE),
         ENG_MOT_IND VARCHAR2(10 BYTE)
    Insert into VEH_ENG_SUB (ENG_SUBCLASS,ENG_MOT_IND) values ('ENGSUB001','MOT01');
    Insert into VEH_ENG_SUB (ENG_SUBCLASS,ENG_MOT_IND) values ('ENGSUB001','MOT02');
    *VEH_ENG_IND( Detail table for engine subclass)*
      CREATE TABLE VEH_ENG_IND
       (     "ENG_SUBCLASS" VARCHAR2(50 BYTE),
         "ENG_IND" VARCHAR2(10 BYTE)
    Insert into VEH_ENG_IND (ENG_SUBCLASS,ENG_IND) values ('ENGSUB001','1');
    Insert into VEH_ENG_IND (ENG_SUBCLASS,ENG_IND) values ('ENGSUB001','2');
    *VEH_AXIS( Master table for Engine Axis)*
    CREATE TABLE VEH_AXIS
       (     ENG_AXIS VARCHAR2(50 BYTE),
         AXIS_MOT_IND VARCHAR2(10 BYTE)
    Insert into VEH_AXIS (ENG_AXIS,AXIS_MOT_IND) values ('ENGAXIS001','MOT01');
    Insert into VEH_AXIS (ENG_AXIS,AXIS_MOT_IND) values ('ENGAXIS002','MOT02');
    *VEH_AXIS_IND( Details table for engine axis)*
    CREATE TABLE VEH_AXIS_IND
       (     ENG_AXIS VARCHAR2(50 BYTE),
         ENG_IND VARCHAR2(10 BYTE)
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS001','1');
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS001','2');
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS001','3');
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS001','4');
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS002','5');
    Insert into VEH_AXIS_IND (ENG_AXIS,ENG_IND) values ('ENGAXIS002','6');
    Condition 1
    if i select only ENGINE_SUBCLASS='ENGSUB001' then
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_eng_sub vsub,
    veh_eng_ind  vind
    WHERE (v.vip_mot_ind= vsub.eng_mot_ind
    and   v.vip_ind=vind.eng_ind
    and    vsub.eng_subclass= vind.eng_subclass
    AND vsub.eng_subclass='ENGSUB001' )output is
    MOT01     1
    MOT01     2
    Condition 2:if i select only the Engine Axis='ENGAXIS002' then the
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_axis  vaxis,
    veh_axis_ind vaind
    WHERE  v.vip_mot_ind= vaxis.axis_mot_ind
    and   v.vip_ind= vaind.eng_ind
    and   vaind.eng_axis= vaxis.eng_axis
    and   vaxis.eng_axis='ENGAXIS002';MOT02     5
    MOT02     6
    Condition 3:
    BOTH ENGINE AXIS AND ENGINE SUBCLASS
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_eng_sub vsub,
    veh_eng_ind  vind,
    veh_axis  vaxis,
    veh_axis_ind vaind
    WHERE (v.vip_mot_ind= vsub.eng_mot_ind
    and   v.vip_ind=vind.eng_ind
    and    vsub.eng_subclass= vind.eng_subclass
    AND vsub.eng_subclass='ENGSUB001' )
    AND  ( v.vip_mot_ind= vaxis.axis_mot_ind
    and   v.vip_ind= vaind.eng_ind
    and   vaind.eng_axis= vaxis.eng_axis
    and   vaxis.eng_axis='ENGAXIS002');Null values returned. this is correct.
    But the query PERFORMANCE fails in OR CONDITON as below
    Condition 4;
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_eng_sub vsub,
    veh_eng_ind  vind,
    veh_axis  vaxis,
    veh_axis_ind vaind
    WHERE (v.vip_mot_ind= vsub.eng_mot_ind
    and   v.vip_ind=vind.eng_ind
    and    vsub.eng_subclass= vind.eng_subclass
    AND vsub.eng_subclass='ENGSUB001' )
    OR  ( v.vip_mot_ind= vaxis.axis_mot_ind
    and   v.vip_ind= vaind.eng_ind
    and   vaind.eng_axis= vaxis.eng_axis
    and   vaxis.eng_axis='ENGAXIS002');output
    MOT02     5
    MOT02     5
    MOT02     5
    MOT02     5
    MOT02     6
    MOT02     6
    MOT02     6
    MOT02     6
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     1
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    MOT01     2
    This is sample example. when i implement in huge table with partition this scennario takes much time even 2 hours to run.
    i want the output must be as below if i use OR condition like condition 4
    MOT01     1
    MOT01     2
    MOT02     5
    MOT02     6
    Gurus and experts pls help me to solve this problem. Dont give any suggestion like
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_axis  vaxis,
    veh_axis_ind vaind
    WHERE  v.vip_mot_ind= vaxis.axis_mot_ind
    and   v.vip_ind= vaind.eng_ind
    and   vaind.eng_axis= vaxis.eng_axis
    and   vaxis.eng_axis='ENGAXIS002'
    union
    SELECT  vip_mot_ind,vip_ind
    FROM veh_main V,
    veh_eng_sub vsub,
    veh_eng_ind  vind
    WHERE (v.vip_mot_ind= vsub.eng_mot_ind
    and   v.vip_ind=vind.eng_ind
    and    vsub.eng_subclass= vind.eng_subclass
    AND vsub.eng_subclass='ENGSUB001' )
    }this will give correct result...
    MOT01     1
    MOT01     2
    MOT02     5
    MOT02     6
    but the problem is we cannot implement this in query. because query get framed at runtime there will be so many implement has to be done. other than UNION pls give me more suggesion
    waiting..
    S
    Edited by: A Beginner on Sep 11, 2010 12:51 AM

    create a view v1 with all the joins
    select * from v1 where eng_subclass='ENGSUB001'
    union
    select * from v1 where eng_axis='ENGAXIS002'
    If you really do not like the direct access with union, try this
    select * from v1
    where vsub_PK in (select vsub_PK from v1 where eng_subclass='ENGSUB001' )
    OR vsub_PK in (select vsub_PK from v1 where eng_axis='ENGAXIS002')
    --vsub_PK is the primary key of table vsub                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to get week number from date

    Hi,
       please mention how to get the number of week from a particular date using fn module?

    Hi Debarshi,
                       Use FM <b>DATE_GET_WEEK</b>
    Reward points if helpful.
    Regards,
    Hemant

  • How to get week number and day in my result?

    hi experts, i have given the data is ID and DATE(yyyymmdd),i want to get output like ID,DATE,WEEKNO,YEAR,MONTH,DAY. how to get this output.
    thanks & regards
    vijay

    In a routine transformation you can call function
    DATE_GET_WEEK
    to get the week number from the date.
    To determ the others, use the substring
    YEAR = DATE(4)
    MONTH = DATE+4(2)
    DAY = DATE+6(2)

  • Get Week Number of Current Month

    How can I get the week number of the current month (1-5)?
    This is what I have tried and I'm not getting the expected
    results.

    quote:
    Originally posted by:
    DJ5MD
    Does your go 1-5 since it's only 30 days? Is that the
    difference?
    I think he was referring to your comment "How can I get the
    week number of the current month (1-5)?". Some months can have 6
    weeks so you should take that into account.
    Both the function from cflib.org and his code should return 6
    for 2007-09-30.

  • Query to get Cust Number,Cust Name,Bill_to _address,Ship_to_address

    Hello Friends,
    I am new to oracle apps,i am facing difficult in writing the query to get the following information -
    Cust Number,
    Cust Name,
    Bill_to _address,
    Ship_to_address
    Kindly share if you any information related to this.
    Thanks in advance!
    Ramya Nomula

    Ramya
    Use
    select
    a.party_name,b.account_number,
    f.address1.......
    from
    hz_parties a, --get party name
    hz_cust_accounts b, --get account number
    hz_cust_acct_sites_all c, -- site information
    hz_cust_site_uses_all d, --Site usage information 'BILL_TO' OR 'SHIP_TO'
    hz_party_sites_all e, --to get to the address string
    hz_locations f --address string is here
    where
    a.party_id=b.party_id
    and b.cust_account_id=c.cust_account_id
    and c.cust_acct_site_id=b.cust_acct_site_Id
    and d.site_usage_code='BILL_TO'
    and c.party_site_id=e.party_site_id
    and e.location_id=f.location_id;
    Play around with the above for status also so that you get to the exact query.
    Thanks
    Nagamohan

  • Get week number for any given date

    How to get a week number in Java?

    / ====================================================
    Method: Get the desired Date format for the date
    Developed By: Sandip Waghole [29-Jan-2010]
    ==================================================== /
    public String getWeekNo(String strDate)
    // input Date Format : M/dd/yyyy
    int weekNo=0,i=0;
    String strWeekNo=null;
    int noOfDaysInTheYear=365;
    int WEEK_STARTS_ON = 1; // Define the day on which week starts Sunday/Monday 1:Sunday 2:Monday
    int firstDayNoInFirstWeekOfPresentYear=0; // Inititalize teh day on which week is starting in present year
    int firstDayOfPresentYear=0; // Inititlize the 1st day of the present year whether Sunday/Monday/.....
    int[] monthDaysArray = {31,28,31,30,31,30,31,31,30,31,30,31}; // Define array of the days as per months
    int todaysDayNoInPresentYear=0;
    int daysLateByFirstWeekStartedAfterYearStarted=0;
    int intTemp=0;
    //strDate="08/24/2000"; // For test purpose
    StringTokenizer strDateTok = new StringTokenizer(strDate, "/ ");
    int month = Integer.parseInt(strDateTok.nextToken());
    int day= Integer.parseInt(strDateTok.nextToken());
    int year = Integer.parseInt(strDateTok.nextToken());
    GregorianCalendar cal = new GregorianCalendar();
    // Check if present year is leap year
    boolean boolIsLeapYear = cal.isLeapYear(year);
    // If it is boolean year then add 1 to total days in the year & add one more day to february
    if(boolIsLeapYear)
    noOfDaysInTheYear=noOfDaysInTheYear+1;
    monthDaysArray[1]=monthDaysArray[1]1;
    // Find the 1st day of this year
    Calendar calObj = new GregorianCalendar(year, Calendar.JANUARY, 1);
    firstDayOfPresentYear = calObj.get(Calendar.DAY_OF_WEEK);
    int intRemoveNoOfDaysFromWeek=0;
    // # Find the day no of prsent day
    for(i=0;i<month;i+) // get no of days till present year
    intTemp = intTemp monthDaysArray;
    todaysDayNoInPresentYear = intTemp - (monthDaysArray[month-1]-day);
    if(firstDayOfPresentYear==6 || firstDayOfPresentYear==7) // If first Day is Friday or Saturday then it is week
    // Identify the the day no on which 1st week of present year is starting
    firstDayNoInFirstWeekOfPresentYear = 7 - firstDayOfPresentYear WEEK_STARTS_ON 1;
    // Find delay in the 1st week start after r=the year start
    daysLateByFirstWeekStartedAfterYearStarted = firstDayNoInFirstWeekOfPresentYear - 1;
    // Now week is starting from Sunday
    weekNo = (Integer)((todaysDayNoInPresentYear-daysLateByFirstWeekStartedAfterYearStarted)/7);
    // Find the day no of today
    intTemp = (todaysDayNoInPresentYear-daysLateByFirstWeekStartedAfterYearStarted) % 7;
    if(intTemp > 0)
    weekNo=weekNo+1;
    else
    weekNo=weekNo;
    else
    // 1st week is starting on 1st Of January
    firstDayNoInFirstWeekOfPresentYear=firstDayOfPresentYear;
    // Remove no. of days from the 1st week as week is starting from odd Sunday/Monday/Tuesday/Wednesday/Thursday
    intRemoveNoOfDaysFromWeek = 7-firstDayOfPresentYear 1; // 1 added as include start day also
    // So one week will be added in no. of weeks
    weekNo = (Integer)((todaysDayNoInPresentYear-intRemoveNoOfDaysFromWeek)/7);
    // Find the day no of today
    intTemp = (todaysDayNoInPresentYear-intRemoveNoOfDaysFromWeek) % 7;
    weekNo = weekNo +1; // As 1st weeks days are reduced from the todays day no in the year
    if(intTemp > 0)
    weekNo=weekNo+1;
    else
    weekNo=weekNo;
    // Remove the no. of days from the week 1
    strWeekNo=Integer.toString(weekNo);
    return strWeekNo;
    // Any issues please mail on [email protected]

  • ABAP Get Week Number for a Given Date.

    Hi All,
    I want to calculate week number for given date.
    SAP has provided function modules like DATE_GET_WEEK.. Etc are giving week number. taking default start day as Monday. But for my requirement is calculate week number based on start day as Sunday.
    Please let me know if we have any custom logic ??
    Thanks & Regards
    Vasu Yadav

    Hi Vasu,
    SAP standard functionality takes MONDAY as first day.
    But if you want then you can change it to SUNDAY by implementing BADI CALENDAR_DEFINITION. Create a new implementation for method IF_CALENDAR_DEFINITION~GET_FIRST_DAY_OF_WEEK and assign value as SUNDAY.
    Hope it solves your problem.
    Thanks
    Saurabh Kabra

  • TO_CHAR with dates to get week number issue

    I am trying to build a report showing weekly sales data and running into an issue with Dates and TO_CHAR..
    Using the date 9/29/2007, I expect the return from the following to be 4:
    SELECT TO_CHAR('09/29/2007','W') FROM DUAL
    However, it returns 5!!! Testing further I tried the next day, since it is a Sunday, it should be the start of the next week, 5..
    SELECT TO_CHAR('09/30/2007','W') FROM DUAL.. I do get a 5..
    I understand that the implementation of TO_CHAR with the 'W' parameter defaults a week start on what ever the first day of the month is, but I need a method that is more calendar like (Sunday is the start of a week, Saturday end of the week).
    Anyone have a nifty solution?
    Thank you,
    Tony Miller
    UTMB/EHN

    This works pretty well. Please note that it is zero based, so add 1 if you want it to start with the first week as 1.
    WITH TAB AS
      (SELECT TO_DATE('12/01/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/02/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/03/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/04/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/05/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/06/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/07/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/08/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/09/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/29/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/30/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL UNION ALL
       SELECT TO_DATE('12/31/2007', 'mm/dd/yyyy') DATE_COL FROM DUAL)
    SELECT DATE_COL,
      TO_CHAR(DATE_COL, 'ww') W_IN_YEAR,
      TO_CHAR(TRUNC(DATE_COL, 'month'), 'ww') W1_OF_MONTH,
      TO_NUMBER(TO_CHAR(DATE_COL, 'ww')) -
      TO_NUMBER(TO_CHAR(TRUNC(DATE_COL, 'month'), 'ww')) MY_WEEK,
      TO_CHAR(DATE_COL, 'W') ORACLE_WEEK
    FROM TAB
    DATE_COL     W_IN_YEAR W1_OF_MONTH MY_WEEK  ORACLE_WEEK
    01-DEC-2007  48        48          0        1          
    02-DEC-2007  48        48          0        1          
    03-DEC-2007  49        48          1        1          
    04-DEC-2007  49        48          1        1          
    05-DEC-2007  49        48          1        1          
    06-DEC-2007  49        48          1        1          
    07-DEC-2007  49        48          1        1          
    08-DEC-2007  49        48          1        2          
    09-DEC-2007  49        48          1        2          
    29-DEC-2007  52        48          4        5          
    30-DEC-2007  52        48          4        5          
    31-DEC-2007  53        48          5        5          
    12 rows selected

  • Problem in getting week number

    I am facing a problem regarding use of Calendar object.
    I have used it to calculate Week_Of_The_Year where
    the week day starts with Monday. (Mon - Sun)
    Its working perfectly except the last week of this year i.e. 2004
    where I want it to return fiscal week 53 , but instead its returning
    1 (as because the January 1-2 ' 2005 lies in that specific week.)
    and in the same manner its giving problem for the first week of the
    next year i.e. 2005 .Its returning Fiscal week(FW) 2 for the
    January 3-9 ' 2005 period where as I want it to return FW 1 for that
    week.
    here is the code snippet,
             public int getWeekNumber(String dateString) {
              Calendar cal = Calendar.getInstance();
              java.util.Date dt = new java.util.Date(dateString);
              cal.setTime(dt);
              cal.setFirstDayOfWeek(Calendar.MONDAY);
              int weekNumber = cal.get(Calendar.WEEK_OF_YEAR);
              return weekNumber;
    where as date string is in mm/dd/yyyy pattern.
    Please, let me know if I could clearly explain the problem to you .
    I am stuck with this problem with quite some time. If anybody can crack this
    problem i will be grateful.
    Thanks in advance.

    Haven't tried it, but have you tried playing with Calendar's setMinimalDaysInFirstWeek method? That is supposed to specify how many days must be in that first week of the year. You may need to read the Calendar API more closely.

  • How to run i tunes version 10.6.3 on mac os x 10.6, 32 bit mode? it gives mesg to go into 32 bit mode but i cant get into it pls help

    how to run i tunes version 10.6.3 on mac os x 10.6, 32 bit mode? it is downloded in 64 bit mode. when i start i tunes it gives mesg to go into 32 bit mode by going into finder, choose the the "get info command" then check the check box "32 bit mode in window" but i am not finding the check box of 32 bit mode. pls help

    That crash appears to be casued by the Facebook plug-in.
    Create a new account (systempreferences -> accounts or Users & Groups on 10.7 and 10.8), make a new Library in that account, import some shots  and see if the problem is repeated there. If it is, then a re-install of the app might be indicated. If it's not, then it's likely the app is okay and the problem is something in the main account.

Maybe you are looking for

  • Error: JAVA_HOME is not defined correctly - While running ant.

    I have upgraded the JDK 1.5 Update 10 to Update 14. After upgrading the ant is failing when using with cygwin. It's giving the below error message: Error: JAVA_HOME is not defined correctly. We cannot execute /cygdrive/c/Java/jdk14/bin/java The JAVA_

  • Problems Activating Iphone

    Hello, I am having a problem with my iphone c i somehow reset it or something and now i have to activate my apple id. Well the problem with that is that i forgot completely what my id was that i used for this phone and i have no idea what email i use

  • FCE4 output from AVCHD to HDV

    Hi I'm currently using a Sony HDR-SR10e camcorder AVCHD format and editing in Final Cut Express 4. I wanting to use a Sony M15 HDV deck to capture in HDV mode but not having much success. Is there any settings I need to enable me to do this. All my f

  • Where can I find firefox 3.0 ?

    Hello, This can seem strange but I need to install FF '''3.0''' :( on my Windows 7 system in order to test my Javascript application (customer constraint). Where can I find it ? Is there any way to install it on a PC where FF 5.0 already installed ?

  • Third party Sales order related issue

    Hi, We are facing a strange issue Once a sales order is entered, purchase req is   created, the buyer then creates the purchase order.  Once the PO is generated, the req is deleted.  This in turns creates an incomplete order and the buyer cannot PGI