How to get ISO week number?

hi,
I need to interact with a server that expects to be passed the ISO week number. The Calendar class doesn't seem to support this though (although the documentation claims that it is ISO 8601 compliant).
For instance the web page here gives today (Jan 10th 2005) as being in Week 2
http://personal.ecu.edu/mccartyr/isowdcal.html
but this code snippet returns "Week 3"
import java.util.*;
public class WeekOfYear {
     public static void main(String[]arg) {
          Calendar c = Calendar.getInstance();
          System.out.println("Week "+c.get(Calendar.WEEK_OF_YEAR));
}does anyone know a correct way of getting the ISO 8601 Week number without reimplenting a lot of delicate code?
thanks,
asjf
ps. of course for now, and the rest of 2005, i'm going to hard code subtracting 1 as a gratuitous hack :o)

hi,
thanks - i did check the docs :)
the problem is that Calendar's idea of what the first week in the year is differs from the ISO standard
the problem is that the ISO standard defines the first week of the year as that containing the first Thursday (ie some days may become part of the previous year's weeks)
and Calendar defines it as the docs state - so to change the value returned would mean you having to change the "FirstDayOfWeek" or the "MinimalDaysInFirstWeek" - which (without checking recently) I think the ISO standard also defines so you can't safely change these
I might raise a RFE against Calendar about this in a week or two since it seems quite important?
thanks,
asjf

Similar Messages

  • How to get the week number for a given date?

    hi guys,
    what is coding to get the week number for a given date?
    For example, 1/1/05 is week 1. then 8/1/05 is week 2.

    The second parameter to pass to the method is supposed to be one of the month constants JANUARY - DECEMBER. It happens to be that their numerical values are 0-11, not 1-12, so your "12" refers to the "13th" month of the year.
    givenDate = new GregorianCalendar(2003, Calendar.DECEMBER, 31);
    If you want to construct dates and times from strings like you seem to be, look into SimpleDateFormat http://javaalmanac.com/egs/java.text/ParseTime.html
    (even still I got WEEK_OF_YEAR as 1 which is true but not really what I expected, excuse my previous reply but I wanted to check the facts before posting this)

  • How to get the week number of year from a Date object?

    Hi!
    I would like to know the week number of the year from a specified Date.
    I dont know how to set the first day of week, and set the minimum days of a week.
    I want to use Monday for first day of week, and at least 4 days of month in a week.
    For example if its 1st, January is Friday, then the first week starts on 4th, Monday.
    Anyone can help?

    Sorry. I should think before I move.
         public static int getWeekOfYear(Date date) {
             Calendar calendar = Calendar.getInstance();
             calendar.setTime(date);
             calendar.setFirstDayOfWeek(Calendar.MONDAY);
             calendar.setMinimalDaysInFirstWeek(4);
             return calendar.get(Calendar.WEEK_OF_YEAR);
         }

  • How to get a week number  for the year using oracle sql query?

    hi everyone,
    i have the requirement to find the week number for the calender..
    so that week number should start with 01 when the year starts and it should end with week end date(that is first saturday of the january month).. so next week number starts with sunday and ends with saturday ,continously.. in the end date of the year it should not be 'saturday' but week number should end with last date of the year.. again in the next year it should start with '01'.
    for example:
    01-JAN-13 tuesday 01
    02-JAN-13 wednesday 01
    03-JAN-13 thursday 01
    04-JAN-13 friday 01
    05-JAN-13 saturday 01
    06-JAN-13 sunday 02
    07-JAN-13 monday 02
    26-DEC-13 thursday 52
    27-DEC-13 friday 52
    28-DEC-13 saturday 52
    29-DEC-13 sunday 53
    30-DEC-13 monday 53
    31-DEC-13 tuesday 53
    01-JAN-14 wednesday 01
    02-JAN-14 thursday 01
    how can i achieve this, can anyone please help me out on this..
    i have a query that starts with 01 when year starts but it gives problem in the end of the year .. described below with a query..
    select mydate,
    to_char(mydate,'day') as weekday,
    to_char(next_day(mydate,'sunday'),'iw') as week_num
    FROM ( SELECT TRUNC (SYSDATE, 'yy') - 1 + LEVEL AS mydate
    FROM dual
    CONNECT BY LEVEL <= (SELECT TRUNC (ADD_MONTHS (SYSDATE, 24), 'yy')
    - TRUNC (SYSDATE, 'yy')
    FROM DUAL))
    this query gives date, weekday and week_num for 2 years 2013 and 2014,
    when i run this query ,at the end of the 2013 it gives the result as,
    26-DEC-13     thursday      52
    27-DEC-13     friday      52
    28-DEC-13     saturday      52
    29-DEC-13     sunday      01
    30-DEC-13     monday      01
    31-DEC-13     tuesday      01
    01-JAN-14     wednesday     01
    02-JAN-14     thursday      01
    for dates 29 ,30,31st it should give 53 .. how can i achieve that using this this query .. can any one help me out on this please...
    thanks,
    pradeep

    I tried with the IW ...
    it is giving week_id for the year.
    select
    mydate,
    to_char(mydate,'day'),
    case when mydate between trunc(mydate,'yyyy') and next_day(trunc(mydate,'yyyy'),'saturday')
    then to_number(to_char(mydate,'yyyy')||to_char(trunc(mydate,'yyyy'),'iw'))
    when mydate between next_day(trunc(mydate,'yyyy'),'saturday') and trunc(add_months(trunc(mydate,'yyyy'),12)-1,'d')-1
    then to_number(to_char(mydate,'yyyy')||to_char(next_day(mydate,'sunday'),'iw'))
    when mydate between trunc(add_months(trunc(mydate,'yyyy'),12)-1,'d') and add_months(trunc(mydate,'yyyy'),12)-1
    then to_number(to_char(mydate,'yyyy')||to_char(trunc(add_months(trunc(mydate,'yyyy'),12)-1,'d')-1,'iw')+1) end as WEEK_ID
    FROM ( SELECT TRUNC (SYSDATE, 'yy') - 1 + LEVEL AS mydate
    FROM dual
    CONNECT BY LEVEL <= (SELECT TRUNC (ADD_MONTHS (SYSDATE, 24), 'yy')
    - TRUNC (SYSDATE, 'yy')
    FROM DUAL
    ))

  • How to format a date to display the ISO week number in BI Publisher ?

    Hi there,
    I need to format a date to display the ISO week number in BI Publisher.
    I've tried the following <?format-date:NEED_BY_DATE;'WW'?>, but it returns a week number (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year, which is not what I want.
    I want the ISO week number (1-52 or 1-53), the one implemented by the 'IW' format mask of the Oracle PL/SQL TO_CHAR() function for example.
    I've tried using 'IW' format mask, but it is not recognised by BI Publisher.
    Also, as I'm working on an RTF template, I've tried 'IW' as MS Word date format, but it is not recognised by MS Word :-((
    Any help would be much appreciated,
    Regards - Hugues

    Hi,
    Thank you for the post.
    The thing is I don't have access to the query, unless I modify a standard E-Businees Suite view (one of those used to generate the PO document in Purchasing).
    Regards - Hugues

  • Display ISO week number instead of date on x axis in Bar Chart

    Hi,
    I've created a simple SSRS report based on bar chart that shows several milestones. Everything works fine for me except I’m not able to convert the date into ISO week number format.
    I played around with different approaches. I was able to convert the date into an ISO week Format directly on the SQL Server. That
    wasn't a problem.
    But unfortunately I’m not able to display the week number on the horizontal axis in my Bar Chart. I tried both fields: TaskFinishDate and TaskFinishDateMS...
    I would like to show the ISO week number instead of the date within the Bar Chart on the horizontal axis.
    Any ideas/hints/help is really appreciated!
    Thanks,
    Mike

    Hi Mike,
    Per my understanding that you want to get the week number of the year based on the field "TaskFinishDate" which is datetime type and display the week number in the x-axis instead of the field "TaskFinishDate", right?
    I have check the snapshot you have provided and it seems you have change the format of the datetime field in the x-axis like "dd.MM.YYYY", If you can't make the week number to display correctly in the x-axis, the issue can be caused by you haven't
    change the format to Number in the category.
    Details information below for you reference:
    I assume you have use expression in the Label like below to convert the datatime TaskFinishDate in to ISO week number like below:
    =DatePart(DateInterval.WeekOfYear,Fields!TaskFinishDate.Value)
    or
    =DatePart("ww",Fields!TaskFinishDate.Value)
    Right click the X-axis and select the "Horizontal Axis Properties", then click the Number to change the format to "Number" as below:
    Preview you will get the weeknumber display in the x-axis correctly.
    If you still have any problem, please feel to ask.
    Regards,
    Vicky Liu
    If you have any feedback on our support, please click
    here.
    Vicky Liu
    TechNet Community Support

  • How to get a random number in a range?

    as title
    how to get a random number in a range?
    like 2000~3000 thks :)

    int between 10 and 20 with the method Math.random():
    public class Rnd
         // Test
         public static void main(String[] args)
             int start=10, end = 30;
             for (int i = 0; i < 10; i++)
                int n = (int)(start + Math.random() * (end-start));
                System.out.println(n);
    }best regards.

  • How to get the total number of pages printed in a report?

    Hi All,
    I have a requirement where I need to print a frame of fields only in the last page. Unfortunately I cannot use the 'Print Object On' property as it doesnt work in my case. So, I am planning to write a format trigger on the frame to return TRUE if the page is the last physical page. Now, I need to know how to get the total number of physical pages that will get printed in the report so that I can use this to manipulate the frame. I was planning to use the 'Total Physical Pages' built-in, but it seems like I can just use it to print in a field and I can't use this field's value anywhere in the plsql code (formula column function/format trigger) in the report. Is there anyway to get the total number of pages printed in the report which can be used in the report plsql code?
    Thanks,
    Srini.

    i found the solution, thanks

  • How to get the page number in the break section?

    Hi expert,
    The user wants the page number came right after the Break group name if the break section contains more than 1 page. E.g.
    ABC Compnay
    XXXXXXXXXXX XXXXXXXX
    XXXXXXXXXX XXXXXXXXXXXX
    BCD Company, p 1
    XXXXXXXXXXX XXXXXXXX
    XXXXXXXXXX XXXXXXXXXXXX
    BCD Company, p 2
    XXXXXXXXXXX XXXXXXXX
    XXXXXXXXXX XXXXXXXXXXXX
    CDE Company
    XXXXXXXXXXX XXXXXXXX
    XXXXXXXXXX XXXXXXXXXXXX
    How to get the page number in section break level?

    Hi Wes
    * Create a Field on the margin.
    * Set its "Source" to "Page Number"/"Physical Page Number".
    * Click "Page Numbering" button.
    * In "Reset At" list box, choose the Repeating frame that surrounds your detail group in the layout.
    This should cause Reports to increment the page number until the "Company" repeating frame resets.
    Regards
    Sripathy

  • How to get payment document number from paid column in monthly invoice

    Dear experts
    I use SBO japan version and i need to know how to get payment document number from paid column in monthly invoice ?
    in table MIN1, only contain invoice and credit note document number, there is no payment document number
    thank you for your help
    Best Regards
    JeiMing

    Dear Gordon
    Yeah, you are right, i can use field MIentry in RCT2
    thank you
    Best regards
    jeiming

  • How to get purchase order number from delivery number?

    hi all,
    how to get purchase order number and item if i have only delivery.
    and in same way how to get po number and item if i know only batch number.
    kindly give me some solution i need this urgently.
    thanks in advance.

    Check the logic below:
    * Selecting the Sales Documents from VBFA for corresponding Invoice
        SELECT vbelv
                     posnv
          FROM vbfa
          INTO TABLE gt_itab3
         WHERE vbeln EQ gt_itab5-vbeln
           AND posnn EQ gt_itab5-posnr
           AND vbtyp_n EQ 'J'.
        IF sy-subrc EQ zero.
          SORT gt_itab3 BY vbelv posnv.
        ENDIF.
      ENDIF.
      IF NOT gt_itab3 IS INITIAL.
    * Selecting the Purchase Orders from VBFA for corresponding Sales Documents
        SELECT vbeln
               posnn
          FROM vbfa
          INTO TABLE gt_itab4
       FOR ALL ENTRIES IN gt_itab3
         WHERE vbelv EQ gt_itab3-vbelv
           AND posnv EQ gt_itab3-posnv
           AND vbtyp_n EQ 'V'.
        IF sy-subrc EQ 0.
          SORT gt_itab4 BY vbeln posnn.
        ENDIF.
      ENDIF.
    Batch number will be there in delivery item.
    Regards
    Kannaiah

  • How to get Contract Account Number in Service Ticket

    Hi Experts,
    How to get Contract account number in Service Ticket, we are working in ISU environment. when i create the service ticket the contract account number is there in Business agreement number field in service tiket.
    Can anyone tell me how to retrieve that field.
    Answer will be appreciated.
    Praveen

    check tables tfk_buag_ref and fkkvkp

  • How to get the Page Number in CS3 with VB?

    Hi, Everybody
    I use the Visual Basic to read the words and their page number where the Words are at. I want to do it according to Story. Some TextFrame of the Story waw placed in other pages: How can I get the Page number according to the Word that is selected?
    For myStoryCounter = 1 to Document.Stories.Count
    Set myStory = Document.Stories.Item(myStoryCounter)
    For myWordCounter = 1 to myStory.Words.Count
    Set myWord = myStory.Words.Item(myWordCounter)
    myWordContents = myWord.Contents
    Rem ** How to Get the Page Number according to the Word ***
    Next
    Next

    > But I don't understand why Item(1) are set.
    because Word can have more than one parent TextFrame - when split across TextFrames
    only Character have one ParentTextFrame accessed also by ParentTextFrames.Item(1)
    > why Story.TextFrames.Count alway is 0, Is it bug?
    no - it's not bug
    in older IDs - Story.TextFrames collection refer to all TextFrames as containers for Story text
    but in CS3 - collection Story.TextFrames contain all TextFrames inserted as InLine/Anchored objects - same like Story.Rectangles or Story.Ovals
    in CS3 - when you want to refer to TextFrames as containers for Story text - you need to use Story.TextContainers - because now you can link TextFrame and Text-On-Path as Story - Text-On-Path isn't TextFrame
    robin
    www.adobescripts.com

  • How to Get last page number in report 10g

    I want to get last page number in report but Current page number found from srw.get_page_num(n)
    but i want to get last page number for conditional formating like this
    srw.get_page_num(current_page)=last_page
    pls help me how can get last page number;
    pls help;
    thanks in advanced;

    Hi,
    you can use the Property Print Object On for this.
    Regards
    Rainer

  • How to get the document number for a ware house order.

    Hello gurus,
    how to get the document number for a ware house order. [if GI is posted refering that WH order] .. is there any report?
    Thanks in advance

    There are several options.  When you post a Goods Movement, you can use LB12 -display Transfer Requirement for material document or LB11 Display TR for material.
    Depending on how your system is set up you may have gotten a Transfer Order automcatically.  In this case you can look at LT24 - Transfer Order for material.

Maybe you are looking for

  • Error in CMP ORA-00928: missing SELECT keyword

    Hi, I am using WLS 8.1 and with CMP trying to insert records in oracle 8.1. But I am getting error as below. I hv not defined and finder method in the home interface except the default findByPrimaryKey(). javax.transaction.TransactionRolledbackExcept

  • Inventory Stock Initialization not working

    Hello Everyone, I tried to follow the steps of "Inventory Stock Initialization" in ERP but when I see the quantity and value fields (BWMNG and BWGEO) in RSA3, all the values are zero. Can someone tell me where I am going wrong? Here are the steps I a

  • Initiating a deployment task with id 0,1,2,3...same jar file

    I have been deploying a single EJB jar file but my server starts redeploying same jar file until I kill the sever its keep doing this, because it deployed jar (EJB component) once successfully, all of next attempt cause "NameAlreadyBoundException". I

  • HT3625 But my Mac in the Sound Input menu does not have the "Use audio for" menu option.

    I want to use the audio port in my MacBook Pro 13 to record stereo sound, under the Preference>Sound> Input menu, there is no option of "use audio for".

  • Query related to LDAP Authentication

    Hi , We are using LDAP Authentication . I found some users are not able to see particular dashboards. Users are telling they have the position and Setup everything is ok. But still facing problems in getting in dashboards and answars. Please provied