Ask a Question

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

SOLVED
santoshthenge
Occasional Contributor

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.

2018_05_02_19_20_05_Program_Manager.png

1 ACCEPTED SOLUTION

Accepted Solutions
tristaanogre
Community Hero

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

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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

6 REPLIES 6
tristaanogre
Community Hero

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

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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
will_fetherolf
Contributor

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

According to this page (https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/date-and-time-f...), the function returns 0-53 for week numbers.  So, the week containing January 1 would be week 0.  You're right, we're currently in week 18, but the conversion function will always return one less.

tristaanogre
Community Hero

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

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.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

View solution in original post

santoshthenge
Occasional Contributor

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

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

Week No for Current year.pngWeek no for next year.png   

tristaanogre
Community Hero

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

Then, as suggested before, open an issue with support with the appriopriate link at https://support.smartbear.com/message/?prod=TestComplete.  In the meantime, you might have to write some custom conversion to count the weeks to get the number.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
will_fetherolf
Contributor

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

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

cancel
Showing results for 
Search instead for 
Did you mean: