Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Pseudocode:</p> <pre><code>int julian = getDayOfYear(myDate) // Jan 1 = 1, Jan 2 = 2, etc... int dow = getDayOfWeek(myDate) // Sun = 0, Mon = 1, etc... int dowJan1 = getDayOfWeek("1/1/" + thisYear) // find out first of year's day // int badWeekNum = (julian / 7) + 1 // Get our week# (wrong! Don't use this) int weekNum = ((julian + 6) / 7) // probably better. CHECK THIS LINE. (See comments.) if (dow &lt; dowJan1) // adjust for being after Saturday of week #1 ++weekNum; return (weekNum) </code></pre> <p>To clarify, this algorithm assumes you number your weeks like this:</p> <pre><code>S M T W R F S 1 2 3 &lt;-- week #1 4 5 6 7 8 9 10 &lt;-- week #2 [etc.] </code></pre> <p>getDayOfWeek() and getDayOfYear() are standard date-object operations in most languages. If yours doesn't have them, you can count-forward from some known date (Jan 1, 1970 is a common one), after looking up to see what day of the week it was.</p> <p>If you're going to implement your own date counting routines, remember that years that are divisible by 100 are <strong>NOT</strong> leap years, unless they are also divisible by 400. So 1900 was not a leap year, but 2000 was. If you're going to work far back in time, you have to mess with Gregorian vs Julian calendars, etc., see <a href="http://en.wikipedia.org/wiki/Calendar_reform" rel="noreferrer">Wikipedia</a> for loads of info on that.</p> <p><a href="http://www.codeproject.com/KB/datetime/datetimedisc.aspx" rel="noreferrer">This link</a> talks about date/time functions in Windows/C++ in greater detail.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload