13,558,758 members
Alternative Tip/Trick
alternative version

#### Stats

14.7K views
4 bookmarked
Posted 7 Mar 2010
Licenced CPOL

# Week numbers according to ISO8601

, 7 Mar 2010
The code snippet below returns the first Thursday of a given year without iterating anything.DateTime FirstThursday(int year) { DateTime dt=new DateTime(year, 1, 1); return dt.AddDays((11-(int)dt.DayOfWeek)%7);}The formula used may seem a bit bizarre, it computes the distance...
The code snippet below returns the first Thursday of a given year without iterating anything.

```DateTime FirstThursday(int year) {
DateTime dt=new DateTime(year, 1, 1);
}```

The formula used may seem a bit bizarre, it computes the distance between first of January and first Thursday of January, where DayOfWeek.Thursday=4, and another week is added to avoid negative numbers; and eventually a modulo 7 operation fixes everything.

More such stuff can be found here[^].

:)

## About the Author

 Software Developer (Senior) Perceler Belgium
I am an engineer with a background in electronics, software and mathematics.

I develop technical software, both for embedded systems and for desktop equipment. This includes operating systems, communication software, local networks, image processing, machine control, automation, etc.

I have been using all kinds of microcontrollers and microprocessors (Intel 4004/8080/8051/80386/Pentium, Motorola 680x/680x0/ColdFire/PowerPC, Microchip PIC, Altera NIOS, and many more), lots of programming languages (all relevant assemblers, Fortran, Basic, C, Java, C#, and many more), and different operating systems (both proprietary and commercial).

For desktop applications and general development tools I have been using both UNIX systems and Mac/MacOS for many years, but I have switched to x86-based PCs with Windows, Visual Studio and the .NET Framework several years ago.

I specialize in:
- cross-platform development (making software that runs on diverse hardware/OS combinations)
- instruction set simulation
- improving software performance, i.e. making sure the software runs the job at hand in as short a time as possible on the given hardware. This entails algorithm selection, implementation design, accurate measurements, code optimisation, and sometimes implementing virtual machines, applying SIMD technology (such as MMX/SSE), and more.

## Comments and Discussions

 First Prev Next
 Nice Dear ThatsAlok10-Aug-10 0:31 ThatsAlok 10-Aug-10 0:31
 Reason for my vote of 5 very useful johannesnestler3-Aug-10 21:59 johannesnestler 3-Aug-10 21:59
 Last Visit: 31-Dec-99 18:00     Last Update: 26-May-18 12:12 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.