Problem in getting exact week of the year (Reposted)

Hi,
Can somebody respond to my posting please. I am posting it second time since nobody replied me till yet.
I make use of below code to get exact week of the year.
// Assumes the provided date is in 'ddMMM' format
SimpleDateFormat sdf = new SimpleDateFormat ( "ddMMM" );
Date parsedDate = sdf.parse( dateString );
Calendar calendar = Calendar.getInstance();
calendar.setTime( parsedDate );
int week = calendar.get( Calendar.WEEK_OF_YEAR );
Problem which I am facing is that when I pass "dateString" as
"22Mar" then it gives week as 13 instead of 12 for year 2007.
I find out that making use of cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ); statement eradicates the problem, ideally values should be
cal.setFirstDayOfWeek( Calendar.SUNDAY); and cal.setMinimalDaysInFirstWeek( 7); because for US first day of the week should be SUNDAY and minimum number of days should be 7 when I start from Sunday.
Please help me to understand the resolution. Is it correct or not?
Is it possible to solve the problem without specifying cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ).
This seems to be hardcoded for each year.

What am I missing? If you can't accept the ISO rules then you are going to define and implement your own algorithm. UsingSimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" );
        Date parsedDate = sdf.parse( "2007/01/01" );
        Calendar calendar = Calendar.getInstance();
        calendar.setFirstDayOfWeek(Calendar.MONDAY);
        calendar.setTime( parsedDate );
        for (int count = 0; count < 366; count++)
            int week = calendar.get( Calendar.WEEK_OF_YEAR );
            System.out.println(week + "\t" + sdf.format(calendar.getTime()));
            calendar.add(Calendar.DAY_OF_YEAR, 1);
        }I get the week as 12 not 13 but I specified THIS year. If you don't specify a year then, quite rightly, it takes 1970.

Similar Messages

  • Problem in getting exact week of the year

    Hi,
    I have make of use of below code to get exact week of the year.
    Now problem which I am facing is that when I pass "dateString" as
    "22Mar" then it gives week as 13 instead of 12 for year 2007.
    // Assumes the provided date is in 'ddMMM' format
    SimpleDateFormat sdf = new SimpleDateFormat ( "ddMMM" );
    Date parsedDate = sdf.parse( dateString );
    Calendar calendar = Calendar.getInstance();
    calendar.setTime( parsedDate );
    int week = calendar.get( Calendar.WEEK_OF_YEAR );
    I find out that making use of cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ); statement eradicates the problem, ideally values should be
    cal.setFirstDayOfWeek( Calendar.SUNDAY); and cal.setMinimalDaysInFirstWeek( 7); because for US first day of the week should be SUNDAY and minimum number of days should be 7 when I start from Sunday.
    Please help me out to understand the resolution. Is it correct or not?
    Is it possible to solve the problem without specifying cal.setFirstDayOfWeek( Calendar.MONDAY ); and cal.setMinimalDaysInFirstWeek( 4 ). This seems to be hardcoded for each year.
    Thanks in advance...

    What am I missing? If you can't accept the ISO rules then you are going to define and implement your own algorithm. UsingSimpleDateFormat sdf = new SimpleDateFormat( "yyyy/MM/dd" );
            Date parsedDate = sdf.parse( "2007/01/01" );
            Calendar calendar = Calendar.getInstance();
            calendar.setFirstDayOfWeek(Calendar.MONDAY);
            calendar.setTime( parsedDate );
            for (int count = 0; count < 366; count++)
                int week = calendar.get( Calendar.WEEK_OF_YEAR );
                System.out.println(week + "\t" + sdf.format(calendar.getTime()));
                calendar.add(Calendar.DAY_OF_YEAR, 1);
            }I get the week as 12 not 13 but I specified THIS year. If you don't specify a year then, quite rightly, it takes 1970.

  • Convert date to week of the year in Query designer

    Hi,
    I have a requirement to convert date ( a characteristic in the query) to week of the year. For eg. if the date is 01/11/2008 then the week to be displayed is 2008/44.
    Please not that the week is not populated in the Infocube of the same. So i need to convert it in the query designer only.
    Please suggest if you have ideas.
    Regards
    Sapna

    Hi,
    I am trying to get the data by using a virtual characteristic. The problem is i am not able to debug METHOD : IF_EX_RSR_OLAP_BADI~COMPUTE. Can u please help me to reach the breakpoint within this.
    Done....
    Sapna
    Edited by: Sapna Jaiswal on Dec 2, 2008 11:21 AM

  • How to get Open Balance for the year and Total Ending Balance?

    For a given account, how to get Open Balance for the year (Cumulative Ending Balance) and Total Ending Balance (Cumulative Ending Balance)?
    Is there any function module available? or should I read from some tables? Please advice.

    Hello Paul,
    You could try calling one of the following BAPIs - see which one meets your requirement. They are documented well so shouldn't be a problem finding out the correct one for your requirements.
    BAPI_GL_GETGLACCBALANCE      
    BAPI_GL_GETGLACCCURRENTBALANCE
    BAPI_GL_ACC_GETBALANCE      
    BAPI_GL_ACC_GETCURRENTBALANCE
    BAPI_GL_ACC_GETPERIODBALANCES
    BAPI_COND_VAL_DECRE_BALANCES
    You might have to put in some of your own logic after the BAPI call to get what you want.
    Hope this helps,
    Cheers,
    Sougata.
    p.s. Also look at FM FAGL_GET_ACCOUNT_BALANCE
    Edited by: Sougata Chatterjee on May 7, 2008 11:47 AM

  • Problem with getting exact font

    Hello there,
    I am facing strange problem regarding getting exact document font. My sample code is-
             var fontsArr = document.fonts;
             for(var cnt = 0; cnt < fontsArr.length; cnt++){
                var font = fontsArr[cnt];
                alert(font.location); // added for test purpose
         I have  used "Arial-Regular" font in my document. Now when run above code; it alerts as - 
              C:\WINDOWS\Fonts\ariali.ttf   // This is location of Arial-Italic file !!!!!
         I cant understand this problem why it is giving me location of other file when the actual font is available in the location.
    Thanks in advance.

    Hello,
    @Jump_over
    No change. It giving me alert as -
    Arial-Regular
    C:\WINDOWS\Fonts\ariali.ttf
    Cant figure out the problem 

  • Week of the year number appears out of sync with the day of week the week #

    Using the querry below on on a table where the pdate value is a sequential list of dates on an Oracle 11 database the results show the week of the year number changes on the day of the week number 7 not the day of the week number 1. Is there a patch to fix this?
    select
    pdate,
    to_char(pdate,'D') dow,
    to_char(pdate,'Day') Day_name,
    to_char(pdate,'WW') week_of_the_Year
    from daily_period_tab
    where pdate >= '07-jan-11'
    and pdate <= '09-jan-11'
    07-JAN-11     6     Friday      01
    08-JAN-11     7     Saturday      02
    09-JAN-11     1     Sunday      02

    Hi,
    Independent of you NLS settings, you can do this:
    SELECT     TRUNC ( dt + 1
               , 'IW'
               ) - 1     AS sunday
    FROM     table_x;The output in the sunday column will be the Sunday on or before dt. The "magic number" 1 indicates that your week starts 1 day before the ISO week, which starts on Monday.
    Or if you want to use your NLS settings:
    ALTER SESSION     SET NLS_TERRITORY= 'AMERICA';
    SELECT     TRUNC ( dt
               , 'DY'
               )          AS sunday
    FROM    table_x; 
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • Converting "01Jan2008" to week in the year

    Is there a function in Microsoft Excel to convert a date to a week in the year ? I know this is an Oracle site but I figure there is overlap.

    Is there a function in Microsoft Excel to convert a
    date to a week in the year ? I know this is an Oracle
    site but I figure there is overlap.You figure there's an overlap between a relational database and a spreadsheet? If you had said there was an overlap between Oracle and Access I could see where you're coming from but not Oracle and Excel.
    Anyway here's the help from MS Excel...
    WEEKNUM
    Returns a number that indicates where the week falls numerically within a year.
    If this function is not available, and returns the #NAME? error, install and load the Analysis ToolPak add-in.
    How?
    On the Tools menu, click Add-Ins.
    In the Add-Ins available list, select the Analysis ToolPak box, and then click OK.
    If necessary, follow the instructions in the setup program.
    Syntax
    WEEKNUM(serial_num,return_type)
    Serial_num   is a date within the week. Dates should be entered by using the DATE function, or as results of other formulas or functions. For example, use DATE(2008,5,23) for the 23rd day of May, 2008. Problems can occur if dates are entered as text.
    Return_type   is a number that determines on which day the week begins. The default is 1.
    Serial_num Week Begins
    1 Week begins on Sunday. Weekdays are numbered 1 through 7.
    2 Week begins on Monday. Weekdays are numbered 1 through 7.

  • Please help , I have iPhone 4S and have updated to iso6, don't know if that has anything to do with the problem but I can't set the year on date and time to the correct year, it automatically goes to 2578 ? Plz help

    Subject:
    Please help , I have iPhone 4S and have updated to iso6, don't know if that has anything to do with the problem but I can't set the year on date and time to the correct year, it automatically goes to 2578 ? Plz help

    Settings>General>International.
    Set the calendar to "Gregorian". You have it set to Buddhist.

  • How to display the week of the year in a report

    Hi,
    I am doing a report, that needs to break down the information, according to month and then week.
    The week of the year isn't stored anywhere in the database, so i guess it would have to be calculated.
    How would i go about doing this in report?

    hi, yes thats what i mean.
    So if i run my report for 01-feb-2008 to 30-march-2008
    it needs to group the data according to weeks.
    eg. week5 (data)
    week6 (data)
    etc....
    i got this code: select to_char(sysdate, 'IW') from dual;
    will it allow me to do this?

  • Week of the year.

    Hi,
    I need a query for week of the year. i.e. if we pass the date as parameter which week the date belong.
    for ex. 31-AUG-2008 then 35th week, 01-SEP-2008 then 36th week.
    please help to solvel

    Yes, many ways! :-)
    In general built-in functionality such as the IW format on date conversion is the efficient way to do things - why reinvent the wheel? But, if your week numbers are not the standard ones (and lots of organisations run their own calendars) perhaps you could use a join to a look-up table that maps dates to week numbers.

  • When starting imovie I get an error missing quicktime components. To solve the problem I have upgraded to latest version but it didn't help. I want to either solve this problem or get a refund for the useless upgrade.

    when starting imovie I get an error missing quicktime components. To solve the problem I have upgraded to latest version but it didn't help. I want to either solve this problem or get a refund for the useless upgrade.

    Mac OS X 10.6 includes QuickTime versions 10.0 and 7.6.3. The QuickTime 7 player will only be present if a QuickTime Pro key was present at the time of installation, or if specified as part of a custom install, or individually downloaded:
    http://support.apple.com/kb/dl923
    Snow Leopard update 10.6.4 included an update to 7.6.6 (if installed). You can install it from the above link  even though it says for 10.6.3. It's the same version of QuickTime Player 7.6.6.
    (Only QuickTime Player 7.6.3 or 7.6.6 can be updated to "Pro".)
    iMovie does not, AFAIK, use QT 10.

  • How to get last week of the month from a month

    Hello,
    I want to get last week of the month from a month. For example: If Input = April then Output = Week17. Is there any function module? Or what should be the logic inorder to meet such requirement?
    Thanks in advance for your answers.
    Nitin.

    Hi,
    Just cpoy and past this program, and see the result and apply for you requirements.
    Data: ZSCDATUM TYPE SCDATUM,
          ZKWEEK TYPE KWEEK,
          ZDAY TYPE SY-DATUM,
          ZLDAY TYPE SY-DATUM,
          ZWK(3) TYPE N,
          ZM(2) TYPE N.
          ZDAY = SY-DATUM.
          ZM = ZDAY+4(2).
          CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
            EXPORTING
              day_in                  = ZDAY
            IMPORTING
             LAST_DAY_OF_MONTH       =  ZLDAY
    *       EXCEPTIONS
    *         DAY_IN_NOT_VALID        = 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.
          ZSCDATUM = ZLDAY.
          CALL FUNCTION 'DATE_GET_WEEK'
            EXPORTING
              date               = ZSCDATUM
           IMPORTING
             WEEK               = ZKWEEK
    *       EXCEPTIONS
    *         DATE_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.
          ZWK = ZKWEEK+4(2).
          WRITE: ZKWEEK.
          WRITE: ZWK.
    Thanks
    Reddy

  • Get first week of the month

    Hi,
    how to get first week of the month from the query
    i tried this but not gwtting
    SELECT TO_CHAR('09/30/2007','W') FROM DUAL
    thanks
    Edited by: 896398 on Jan 18, 2012 3:17 AM

    896398 wrote:
    how to get first week of the monthAssuming week starts Sunday:
    SELECT  GREATEST(TRUNC(TRUNC(your_date,'MM') + 1,'IW') - 1,TRUNCyour)date,'MM')) week_start_date,
            TRUNC(TRUNC(your_date,'MM') + 1,'IW') - 1 + 6) week_end_date
      FROM  dual
    / If week starts Monday:
    SELECT  GREATEST(TRUNC(TRUNC(your_date,'MM'),'IW'),TRUNCyour)date,'MM')) week_start_date,
            TRUNC(TRUNC(your_date,'MM'),'IW') + 6) week_end_date
      FROM  dual
    / SY.

  • Sql query to get Thursday (Date) for the year 2014

    Hello All,
    I want to get the date for all the Thursdays in the year 2014. How can I achieve this using SQL query? Can anybody give me a hand with this? Thanks.
    Amol

    Hi,
    Check if this can help you
    DECLARE @counter INT
    DECLARE @Date Date
    SELECT @counter = 0
    Select @Date = '20131226'
    WHILE @counter <= 52
    BEGIN
    select Thursday = convert(varchar(10),DATEADD(WEEK,1, @Date),120)
    SELECT @counter = @counter + 1
    Select @Date = DATEADD(WEEK,1, @Date)
    END
    Regards
    Prasad Tandel
    Please dont forget to mark as answer if this helps you :)

  • How to get last day of the year

    Hi All ,
    Thanks in advance ...
    How will I get the last day of the year as I am passing date at run time .
    I can manage to get first day of year by
    SELECT TRUNC(SYSDATE,'YEAR') AS FDAY_YEAR
    from dual
    Thanks in advance
    Regards
    Sachin

      1*  select ADD_MONTHS(trunc(sysdate,'yyyy'),12)-1 dd from dual
    SQL> /
    DD
    31-DEC-2010

Maybe you are looking for

  • Please HELP ME!I can't print a report build with 6i!

    I got Report 6i an report 3.05 in the same machine on Windows NT. But I when I trie to send the ouput to the printer the Dr. Watson Error appear. Whats wrong?

  • Cant import old iPhoto library

    I've just swapped Mac's, and i have copied over my iPhoto library. When i open iPhoto, i can open the library and view it, but when i close the application and restart it, it says it can't find a library. Any help would be appreciated...

  • How can I make a mirror reflection in PSE 11

    How can I make a mirror reflection in PSE 11?

  • Adobe software with file extensions

    I am wondering if there is a chart or some website you can drive me to that would tell me what programs you would use an image for and what images would open in that program.  For example - Indesign - Opens jpg, psd, pdf files - Can use for flyers, p

  • Omni 10 won't power up

    Ordered new power cord because thought that was the issue but Omni 10 will not power up at all. Very frustrating. Have had it for a year and a half and spent good $ on it. Any suggestions?