Forum Discussion

santoshthenge's avatar
santoshthenge
Occasional Contributor
7 years ago

aqConvert.DateTimeToFormatStr(aqDateTime.Today(),"%U") format is not work properly

 Hi All

     aqConvert.DateTimeToFormatStr(aqDateTime.Today(),"%U") is return wrong week number.

 

Ex i have evaluate the function format on date 02.05.2018, So current week number is 18

but this function format return 17 which is wrong. 

 

 This function format is not working properly please refer attached image.

  • tristaanogre's avatar
    tristaanogre
    7 years ago

    nice, will_fetherolf!  Then it's not a bug, just a misunderstanding of what's being returned.

     

    so, %U will still work, you just need to make sure that you add 1 to any result to get the ISO standard week number.

     

    However, it looks like %W is still what you're looking for.  Just did a quick check and %W does it's numbering starting with 1 while %U numbers starting with 0.  That's a documentation problem since %W also seems to note that the week numbering starts with 0.

     

    In short... use %W to get the ISO standardized week number with weeks starting on Monday and numbering starting with 1.

    • tristaanogre's avatar
      tristaanogre
      Esteemed Contributor

      nice, will_fetherolf!  Then it's not a bug, just a misunderstanding of what's being returned.

       

      so, %U will still work, you just need to make sure that you add 1 to any result to get the ISO standard week number.

       

      However, it looks like %W is still what you're looking for.  Just did a quick check and %W does it's numbering starting with 1 while %U numbers starting with 0.  That's a documentation problem since %W also seems to note that the week numbering starts with 0.

       

      In short... use %W to get the ISO standardized week number with weeks starting on Monday and numbering starting with 1.

      • santoshthenge's avatar
        santoshthenge
        Occasional Contributor

        Hello All,

         

         Thank you for reply.

         

        As per the previous conversion. You suggest use %W instead of %U.

        But the %W formater also not working properly.

         

        Please check the below image: %W formater for current year its working correctly but for next year its return wrong value

           

  • It's working correctly, it's simply 0-based. Add 1 to your result and you'll get the correct week number.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Good catch... I'd open a ticket with smartbear at https://support.smartbear.com/message/?prod=TestComplete.

     

    However, I wonder if it has to do with week numbering starting with Sunday versus starting with Monday.  The first full week of 2018 started on Sunday, January 7th so the bug there might simply be having to do with when the week is listed as "starting.

     

    Try using %W instead of %U.  %W gives you the week number assuming weeks start on Monday instead of Sunday.  That is giving the correct value of 18 for May 2nd.