GetWeekNumber

Description Return a short integer value representing the current week number of todays date.
Syntax short GetWeekNumber( void );
Arguments none
Returns short integer value representing the week number of todays date.
Remarks Calculates the ISO-8601 Week Number: 1-1-2005 was weeknumber 53 , 1-1-2009 was weeknumber 1
Example
#include <stdio.h>
#include "lib.h"

// Returns the week number of todays date
short GetWeekNumber( void )
{
    unsigned long ulF, ulS, ulT;
    unsigned long m, y, a;
    unsigned long ulJDN;
    struct date d = {0};

    GetDate( &d );

    a = (14UL - d.da_mon ) / 12UL;
    y = d.da_year + 4800UL - a;
    m = d.da_mon + (12UL*a) - 3UL;

    ulJDN = d.da_day + (( 153UL * m + 2UL) / 5UL) + (365UL * y) + (y / 4UL) - (y / 100UL) + (y / 400UL) - 32045UL;

    ulF = ( ulJDN + 31741UL - ( ulJDN % 7UL )) % 146097UL % 36524UL % 1461UL;
    ulS = ulF / 1460UL;
    ulT = (( ulF - ulS ) % 365UL) + ulS;

    return (short)((ulT / 7UL) + 1UL);
}

void main( void )
{
    struct date d = {0};

    for(;;)
    {
        GetDate( &d );
        printf("%02d-%02d-%04d\nWeek number %d\n", d.da_day, d.da_mon, d.da_year, GetWeekNumber() );

        Delay( 250 ); // wait 5 seconds before update
    }
}