Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!usc!snorkelwacker.mit.edu!thunder.mcrcim.mcgill.edu!quiche!einstein From: einstein@cs.mcgill.ca (Michael CHOWET) Newsgroups: comp.lang.pascal Subject: Re: weeknumber Message-ID: <1991Mar30.075928.8077@cs.mcgill.ca> Date: 30 Mar 91 07:59:28 GMT References: <1991Mar24.195537.9726@cs.umu.se> Sender: news@cs.mcgill.ca (Netnews Administrator) Organization: SOCS, McGill University, Montreal, Canada Lines: 27 In article <1991Mar24.195537.9726@cs.umu.se> dvllhd@cs.umu.se (Lars H{gglund) writes: >I'm looking for an algoritm or code to get the weeknumber from a date. >ex: 1990-12-31 ==> 1 That ought to be simple enough. Just offhand, the following comes to mind: Initialize an array of integers, 12 long. Each entry consists of how many days have elapsed that year till the 1st of that month. Now, the day of the week would be: (( 365 * year )+( year DIV 4 )+( Month_Table [month] )+day+fugefactor)div 7 + 1 Where the fudgefactor is the amount you'd have to slide the whole thing over, or if you want to think more meaningfully, it'd be the day of the week of Jan 1, 0, if the Gregorian calendar had been around then. Note, that this will not work for dates before Pope Gregory modified the calendar (but who wants to know about the middle ages, anyways, right? :) Oh, note it might get outdated some few generations from now, since I heard talk of an additional day added every 2300 years....:) Hmm, come to think of it, when I last tried it, I overflowed. You might have to use LongInt (Turbo) or hope your compiler gives you 31 bits, or calculate the terms separately, mod-ing by 7, THEN add them.