I was wondering if someone can help me out. I'm trying to get an ISO 8601 week number from a TDate. I've had a play with a few suggestions I've found, but none of them seem to reliably return a correct value.
Also, I'd like to know if there's a way to define the 8601 criteria (ie, first monday, week with 4 Jan, first four day week etc) to return the week.
I have looked at the code attached, but I don't necessarily agree with the result it is returning. For instance, why is Jan 1 - 3 returning Week 0? I would have thought it would be week 53 from the year before (although I might be wrong with this assumption).
int DateTimeToISOWeekNumber(TDateTime inputDate)
const int EpochDiff = 25569; // days between 30/12/1899 and 01/01/1970
const int SecsInDay = 86400; // number of seconds in day
typedef struct tm* tmPtr;
short weekNumber = 0;
tmPtr timePtr = NULL;
time_t calendarTime((long)((((double)inputDate) - EpochDiff) * SecsInDay));
timePtr = localtime( &calendarTime );
strftime( tempStr, sizeof(tempStr), "%W", timePtr );
weekNumber = atoi(tempStr);
This code was taken from another EE question and slightly modified.
Any suggestions or hints would be fantastic.