09-13-2024 05:23 PM
Hello colleagues,
On the link below, we have:
Unfortunately the return is the same for both formats.
Source code:
#include <utility.h>
#include <ansi_c.h>
#include <stdio.h>
#include <time.h>
int main (int argc, char *argv[])
{
time_t rawtime;
struct tm *info;
char buffer[80];
time( &rawtime );
info = localtime( &rawtime );
strftime(buffer,80," %U %W ", info);
printf("Week number: %s\n", buffer );
printf("Press the Enter key to exit.");
getchar ();
}
Results:
Week number: 36 36
Press the Enter key to exit.
Expectation:
37 36
09-16-2024 04:20 AM
In my opinion you should not use strftime () to calculate the week number.
On one hand it shows some oddity in the returned week number: here is how it defines week numbers for the first days of 2024
// This code:
strftime (buffer, 80, "%a %b %d: week %U (%W)", info);
// produces this output:
Mon Jan 01: week 00 (00)
Tue Jan 02: week 00 (00)
Wed Jan 03: week 00 (00)
Thu Jan 04: week 00 (00)
Fri Jan 05: week 00 (00)
Sat Jan 06: week 00 (00)
Sun Jan 07: week 01 (00) // <-- !!
Mon Jan 08: week 01 (01)
Tue Jan 09: week 01 (01)
On the other hand it doesn't follow ISO8601 standard for date and time, according to which we are now in week 38 while strftime () returns 37.
Here you can find a useful discussion about this standard and some implementations of it in CVI: I suggest you to use one of them to calculate the week number instead of strftime ().