Number of current week

How do I get the number of current week?

select to_char(sysdate,'W') AS "WEEK OF THE YEAR" from dual (wk of the month)
select to_char(sysdate,'WW') AS "WEEK OF THE YEAR" from dual (wk of the year)

Similar Messages

  • 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]

  • Rollover 18 weeks starting from week number of current month

    Hi,
    I have a requirement as described below.
    Table Name Time:
    Columns: Fiscal Year, Fiscal Month and Fiscal Week
    above table has join with sales table and it contain sales data on week basis. so least granularity of data at week level.
    we have a report with columns fiscal year, actual sales and forcast sales. our requirement is to filter the data with following criteria.
    Current Month Filter
    Jan fiscal week between 1-18 of current year
    Feb fiscal week between 5-23 of current year
    March fiscal week between 9-27 of current year
    November fiscal week between week 44 of current year and week 10 of next year
    December
    so with above requirement we need to filter data with rollover 18 weeks starting from week number of current month
    I tried with timestampadd(sql_tsi_week, interval, week) but it's not working as I expacting. Please provide the code/logic to get it done.
    Appreciate your help.
    Thanks
    Jay.

    Jay wrote:
    I need to get rollover 18 week data at anypoint of time starting with week number of 1st of every month to 18 weeks. read my question again and you will be able to understand.You're kind of missing the point to be honest. It's very hard to answer specific questions without the required information. To answer a question like this we need a minimum of:
    1. Oracle version
    2. Sample data (CREATE TABLE / INSERT statements)
    3. Expected output
    4. Explanation of business rules.
    Alternatively, you can read the link in my original response.
    Please provide the required information and someone can help.

  • Week Number of the current week...URGENT

    hi gurus,
    I want to calculate the week number of the current week as per Fiscal year.
    What variable or the Customer Exit code needs to be written for it?
    regards

    Hi Venu,
       Use the code below. I assume that the client is US based where the Fiscal Year starts 1st October every year.  Just in case the fiscal year starts in some other month then adjust the code (if SY-DATUM+4(2) >= 10.) below. Hope this helps.
    DATA: PFY(8)   TYPE C.
    DATA: CFY(4)   TYPE C.
    DATA: LFY      TYPE I.
    DATA: FYD      TYPE I.
    DATA: TWD      TYPE I.
    DATA: RES      TYPE I.
    if SY-DATUM+4(2) >= 10.
      concatenate SY-DATUM+0(6)
                  '01'
             into PFY.
    else.
      LFY = SY-DATUM+0(4).
      LFY = LFY - 1.
      CFY = LFY.
      concatenate CFY
                  SY-DATUM+4(2)
                  '01'
             into PFY. 
    endif.
    FYD = P_FY.
    TWD = SY-DATUM.
    RES = ( TWD - FYD ) / 7.
    Write: Res.

  • Urgent ---calculate version  from the current week number

    hi,
         i have an requrenment to modify the charasteric routines
      i have xxx table with parameter i have to read this paramater n  if this parameter contains value 'D' then calculate version(eg:- A00,A01 ...) from the current week number.
    pls advice me which FM i have to call or provide me with some sample codeing.
    points wil be rewarded
    ravi

    There is a FM "WEEKNR_GET".
    This will give you the week no. You need to read the param value from the table that you mentioned and call this FM and updat the version.
    You will need a ABAP person to do this.
    Ravi Thothadri

  • Beginner Question: Get current Week Number with Token API

    Is it possible to get the current week (1-52) with the token API?
    I searched the gwtokens.pdf for a suitable method, but haven't found
    something that fit my needs.
    Any idea/suggestion?
    Thank's in advance for your help.

    test wrote:
    > current week
    Use the windows api, or build in functions of the language you code in
    Tommy Mikkelsen
    IT Quality A/S, Denmark
    Novell Support Forums SYSOP / NKP
    Sorry, but no support through email
    Please join http://www.open-horizons.net

  • How to derive  Current week and Number of Weeks for present quarter.

    Hi,
    Currently we are developing a report on Actuals and Planned sales. We have two different data targets to hold these information.
    CRM team will provide targets for BP monthly in CRM table, from where we are extracting the data into BW and report exection frequency is Daily.
    Report Output format:-
    1)  Target1St Month in the quarter,   Target2nd Month in the quarter, Target3rd Month in the quarter, Target Quarter,  Month To date (Taget for Current month - Sales till today),
    Let us assume we are Q1 and user executing this report on end of March Target1 = Jan, Target2 = Feb, Target 3 = March and Quarter target = Target1 + Target2 + Target 3.
    We can achieve this by offset variables.
    But if users are exectuing this report Apr (Q2) then Target1 = Apr target , target2 and target3 =0
    Becoz we are in Q2 and first month of the quarter. If users are executing this report in May target1 should be Apr target and Target 2 = May target and Target3rd month should be Zero.
    2) We have one keyfigure called as Quarter Phased Target = (Quarter target/ No of weeks in current quarter)* current week; For this we have to get No of weeks in every quarter and Curren week (when the reports get executed).
    Let us assume we are executing this report on 25th jan and target for that month = 122units then Quarter phased target =  [(122 + 0 (For Feb)+ 0 (For Mar) )/ 13] X4
    4 is becoz we are in 4th in that quarter,
    13 is becoz no of weeks in that quarter.
    0 (For Feb) - Becoz we are in Jan only..
    Hence please let me know how to get No of weeks in Current quarter and Current week for every quarter..
    All the helpful answers will be awarded with full points.
    Regards,
    suresh

    hi,
    For the first querry.
    the problem is because u are using calmonth.
    Instead of using cal month use fiscal period.
    When u use fiscal period the data will be shown automatically for the Previous months using offsets.
    u have to take taht in ur transformation and should map it to constant value depending on the fiscal periods of ur compnay?
    march- apr,jan-dec etc.
    for teh second querry there would be some charecteristic which might give data in weeks as well just check that and if availabe u can use it.
    am not too sure abt it.

  • Limit values shown in Parameter based on current week

    We have a requirement wherein a parameter can be chosen depending on the current week number.
    For example, today is Feb 3, 2015 (WEEK NUMBER 6), the parameter dropdown should only show
    Week 1
    Week 2
    Week 3
    Week 4
    Week 5
    Upon choosing a specific week, i.e. Week 2, SSRS report will show data where Created By matches the dates in Week 2 which is from January 4, 2015 to January 10, 2015 (SUNDAY is the first day week)
    ----------------------- Sharepoint Newbie

    Hi 120613,
    Because you are using the sharepoint list as the datasource and have some limitation when using query in the dataset, so I recommend you to take reference of the alternative method below which will not effect the filter of the data, you can create an calculated
    field which will use to create the week parameter, the values of the Week list are before the week number of the today's date and get based on the date field in the report.
    Details information below for your reference:
    Create an new dataset(DataSet2) to add the query which have the same structure as in the main dataset but only contain the field "Date".
    Right click the DataSet2 to select the "Add Calculated field" and create an new calculatted fields: name : "Week" and using expression below to get the value(The value will be the week number before the current date's week
    number):
    =IIF(DatePart("ww",Fields!date.Value)<DatePart("ww",Today()),DatePart("ww",Fields!date.Value),Nothing)
    Create the parameter week based on the Calculated field "Week", specify both the Available value and default value by "Get Values from a query"
    Add the filter in the Dataset as below:
    Expression:=DatePart("ww",Fields!Date.Value)
    Operator:In
    Value: [@Week]
    Preview you will got the result as below:
    If the parameter is Multiple and you got some duplicate values, please reference to the article
    Visakh16 have provided.
    If you still have any questions, please feel free to ask.
    Regards
    Vicky Liu
    If you have any feedback on our support, please click
    here.
    Vicky Liu
    TechNet Community Support

  • Number of the week in Ical

    Howcome the number of the week isn´t shown in Ical????

    there's no option for a week view in iCal, but John Maisey wrote this applescript.
    paste it in the Script Editor (Applications --> AppleScript --> Script Editor) and run it once...
    if your weekview starts on an other day change this line:
    set daysText to "MonTueWedThuFriSatSun"
    to (example)
    set daysText to "SunMonTueWedThuFriSat"
    --Copy below this line into Script Editor and click run --
    --Annual Week numbers
    --John Maisey
    --4/2/5
    set numberOfWeeks to 1000 -- change as needed
    set daysText to "MonTueWedThuFriSatSun"
    set aDate to (current date)
    set day of aDate to 1
    set month of aDate to January
    set aDay to weekday of aDate
    set weekNo to 1
    --Day of week as num. starting with 0
    set aDayText to (characters 1 thru 3 of (aDay as text)) as text
    set dayOff to ((offset of aDayText in daysText) - 1) / 3 as integer
    if dayOff is less than 5 then
    set StartDate to aDate - dayOff * days
    else
    set StartDate to aDate + (7 - dayOff) * days
    end if
    tell application "iCal"
    set newCal to make new calendar at end of calendars with properties {title:"Week No."}
    set myCal to (count of every calendar)
    end tell
    repeat with myCount from 1 to numberOfWeeks
    if (month of StartDate is December) and (day of StartDate is greater than 28) then set weekNo to 1
    if (month of StartDate is January) and (day of StartDate is less than 5) then set weekNo to 1
    set weekText to "Week No. " & weekNo
    tell application "iCal"
    tell calendar myCal
    make new event at end of events with properties {start date:StartDate, allday event:true, summary:weekText}
    end tell
    end tell
    set weekNo to weekNo + 1
    set StartDate to StartDate + 7 * days
    end repeat
    --

  • How to know the number of the week in iCal ?

    Hi !
    I'm very enjoying iCal. But, there is something very important for me that I can't find in iCal !
    I need to know the number of the week (in Month, Week or Day views).
    Is that a way to easily see it ?
    Regards,
    ant
    iMac G5   Mac OS X (10.4.2)  

    there's no option for a week view in iCal, but John Maisey wrote this applescript.
    paste it in the Script Editor (Applications --> AppleScript --> Script Editor) and run it once...
    if your weekview starts on an other day change this line:
    set daysText to "MonTueWedThuFriSatSun"
    to (example)
    set daysText to "SunMonTueWedThuFriSat"
    --Copy below this line into Script Editor and click run --
    --Annual Week numbers
    --John Maisey
    --4/2/5
    set numberOfWeeks to 1000 -- change as needed
    set daysText to "MonTueWedThuFriSatSun"
    set aDate to (current date)
    set day of aDate to 1
    set month of aDate to January
    set aDay to weekday of aDate
    set weekNo to 1
    --Day of week as num. starting with 0
    set aDayText to (characters 1 thru 3 of (aDay as text)) as text
    set dayOff to ((offset of aDayText in daysText) - 1) / 3 as integer
    if dayOff is less than 5 then
    set StartDate to aDate - dayOff * days
    else
    set StartDate to aDate + (7 - dayOff) * days
    end if
    tell application "iCal"
    set newCal to make new calendar at end of calendars with properties {title:"Week No."}
    set myCal to (count of every calendar)
    end tell
    repeat with myCount from 1 to numberOfWeeks
    if (month of StartDate is December) and (day of StartDate is greater than 28) then set weekNo to 1
    if (month of StartDate is January) and (day of StartDate is less than 5) then set weekNo to 1
    set weekText to "Week No. " & weekNo
    tell application "iCal"
    tell calendar myCal
    make new event at end of events with properties {start date:StartDate, allday event:true, summary:weekText}
    end tell
    end tell
    set weekNo to weekNo + 1
    set StartDate to StartDate + 7 * days
    end repeat
    --

  • Urgent : Bill Qty based on Fisrt day of Previous week to current week

    Hi,
    I have to create a Restricted Key figure.
    Bill Qty is to be restricted on a day, which is first day of previous week.
    (1) I have restricted KF, with Current Week SAP exit variable.
    (2) Restricted KF, with Calendar Day (Variable ZDATE, customer exit type).
    (3) I have written Customer Exit in CMOD...
    data: LT_RANGE  type  RSR_S_RANGESID,
          LS_VAR_RANGE like RRRANGEEXIT.
    case i_vnam.
    when 'ZDATE'.
    if i_step = 2.
    break-point.
    loop at i_t_var_range into ls_var_range where vnam = '0CWEEK'.
    data: var1(2) type c,
          var2(4) type c,
          var3 LIKE SCAL-WEEK,
          date1 like scal-date,
          DATE2(10) TYPE C,
          MNTH(2) TYPE C,
          DAY(2) TYPE C,
          YEAR(4) TYPE C.
    var1 = ls_var_range-low(2).
    var2 = ls_var_range-low(4).
    concatenate var2 var1 into var3.
    CALL FUNCTION 'WEEK_GET_FIRST_DAY'
      EXPORTING
        WEEK               = var3
    IMPORTING
       DATE               = date1
    EXCEPTIONS
      WEEK_INVALID       = 1
      OTHERS             = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    MNTH = DATE1+4(2).
    DAY = DATE1+6(2).
    YEAR = DATE1+0(4).
    CONCATENATE DAY '/' MNTH '/' YEAR INTO DATE2.
    lt_range-low = date2.
    lt_range-high = date2.
    lt_range-sign = 'I'.
    lt_range-opt = 'eq'.
    append lt_range to e_t_range.
    endloop.
    endif.
    <b>BUT I AM GETTING ERROR -</b>
    00010004              AError for variable in customer enhancement ZDATE
    Please suggest any idea..
    Thanks
    saurabh

    Hi Saurabh,
    Please try this dample code
    WHEN 'ZDATE'.
    DATA: Z_WEEK TYPE SCAL-WEEK.
    *Determine current week from SY-DATUM
            CALL FUNCTION 'DATE_GET_WEEK'
              EXPORTING
                DATE               = SY-DATUM
              IMPORTING
                WEEK               = Z_WEEK.
    *Determine first day of current week 
            CALL FUNCTION 'WEEK_GET_FIRST_DAY'
              EXPORTING
                WEEK = Z_WEEK
              IMPORTING
                DATE = LT_RANGE-LOW.
    LT_RANGE-SIGN = 'I'.
    LT_RANGE-OPT = 'eq'.
    APPEND LT_RANGE TO E_T_RANGE.
    Regards
    Joe

  • Get current week of calendar

    Hi there,
    I want do get the number of the current week into a integer.
    my code:
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="java.util.*"%>
    Calendar calendar = Calendar.getInstance();
    int kw = calendar.WEEK_OF_YEAR;
    session.setAttribute( "show_kw", kw);
    session.setAttribute( "kw", kw); // please do not wonder...I need this, tooLater in my code I want to display this number:
    <p><%
              session.getAttribute("show_kw");
              %></p>But it displays...nothing. Not even a space.
    Any idea, why it isn't showing up the number?
    X--spYro--X

    You need to use the following :
    int kw = calendar.get(Calendar.WEEK_OF_YEAR);instead of
    int kw = calendar.WEEK_OF_YEAR;in your code.
    Hope this helps.
    Thanks

  • Current week?

    Hello Experts,
    I have a day name column and 3 measures query count, row count... and the requirement i have is, i need to get the data about the current week it means when i run the report now i should get only Monday of this week and its row count, query count.. and when i run it tomorrow i should get Monday, Tuesday and when i run it on wednesday Monday, tuesday, Wednesday and so on. Please let me know if i am not clear with my presentation. I am wondering how i can achieve this.
    Thanks,
    RC

    Thanks for your response. I tried your code in the date column filter but its not working, i am getting error not sure if i can just take it and use the same code in the filter criteria. To be more clear i have Day name(Monday, Tuesday..), Day number(for sunday its 1,Monday 2,tuesday 3..) and Date (in the format 11/6/2011...) and the rest are measures,. Basically this is a system generated report like stats report. My requirement is i need to get the current week data as i mentioned earlier if i run the report today it should give me the information only from sunday to today. Please let me know how i can achieve this.
    Thanks,
    RC
    Edited by: user1146711 on Nov 8, 2011 8:55 AM

  • Current week in report page

    Hi Firends,
    I have to write a logic to display in the page whats the current week for this year. I mean if i am talking about 2nd of june 2011, how can i calculate and display what week 2nd june falls in
    Regards

    Hi,
    User_Apex wrote:
    Hi Sybrand Bakker
    I tried this and its showing week 23 but your query is showing as week 22. Please run this and let me know the difference. Thanks in advance
    SELECT ceil(( 7+(trunc(sysdate,'d')-trunc(sysdate,'Y')) )/7) FROM DUAL;(a) That gets the week number based on the calendar year, which begins on January 1.
    ISO Years begin on the Monday closest to January 1 (e.g., Monday, January 3, 2011).
    (b) TRUNC (dt, 'D') is dependent on your NLS settings.
    TO_CHAR (dt, 'IY') (or TRUNC (dt, 'IY') does not depend on your NLS settings.
    (c) Using CEIL (( 7 + ...))) means you'll add a week to the results when dt is not the same day of the week aTRUNC (dt, 'Y'). If you want to use the approach above, you'd be better off using 1 + FLOOR (...)
    Any of the above could cause differences between Sybrad's approach and yours. In this case, it seems to be (c).
    If you want a result based on the calendar year and your NLS settings, then TO_CHAR (dt, 'WW') could be it.
    No kidding, we could help you a lot more if you posted some sample data (CREATE TABLE and INSERT statements), results, and an explanation of how you get those results from that data (e.g., what a "week" means in this context).

  • How to identify which is current week by java.util.Date

    below code wriiten to identify number of weeks in a given month,
    i need current week in a from below code.Can any one help me?
    for(int i=1;i<32;i++){
    Date d = new Date(2005,11,i);
    intMonDtTemp=d.getMonth();
    0-sunday
    1-monday
    5-friday
    6-saturaday
    // number of weeks is based on monday's in given month
    //System.out.println(intMonDtTemp+" at =month dt "+ intMonDt);
    if(intMonDtTemp==intMonDt){
         //System.out.println(i+" = "+ d);
         //System.out.println("MONTHS EQUAL");
         if(d.getDay()==1){
              count= count+1;
    }//end of for
    if(count==5){
         System.out.println(strDt+" = 5 weeks");
    } else {
         System.out.println(strDt+" = 4 weeks");
    }//end of else

    using Calendar, not Date
    import java.util.Calendar;
    class Testing
      public Testing()
        Calendar cal = Calendar.getInstance();
        int month = Calendar.OCTOBER;// months are 0-based 0-11, not 1-12
        cal.set(2005,month,1);
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        if(dayOfWeek > 2) dayOfWeek -= 7;
        cal.add(Calendar.DATE,2 - dayOfWeek);
        int mondaysInMonth = 0;
        while(cal.get(Calendar.MONTH) == month)
          cal.add(Calendar.DATE,7);
          mondaysInMonth++;
        System.out.println("Mondays in month = "+mondaysInMonth);
      public static void main(String[] args){new Testing();}
    }

Maybe you are looking for