473,396 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

algorithm

where can I get code/process/algorithm/or any kind of example to calculate
what day of the week (or month or year) is say 5th of sep in 1767.
Nov 17 '05 #1
7 2278
Pohihihi wrote:
where can I get code/process/algorithm/or any kind of example to calculate
what day of the week (or month or year) is say 5th of sep in 1767.

DateTime dt = new DateTime(1767,9,5);
string s = dt.DayOfWeek.ToString();

HT H,
-rick-
Nov 17 '05 #2
ah, again I did.

I should have said I want to know how to make my own DateTime kind of
function. Just want to know the math behind.
"Rick Lones" <Wr******@YcharterZ.net> wrote in message
news:xs*****************@fe03.lga...
Pohihihi wrote:
where can I get code/process/algorithm/or any kind of example to
calculate what day of the week (or month or year) is say 5th of sep in
1767.

DateTime dt = new DateTime(1767,9,5);
string s = dt.DayOfWeek.ToString();

HT H,
-rick-

Nov 17 '05 #3
Well, given any starting date for which you know the day of week, you would work
with the difference in days modulo 7. But of course the real issue is how to
count up that difference in days. All you really need is the leap year rules:

1) Every year divisible by 4 is a leap year, EXCEPT
2) Every year divisible by 100 is NOT a leap year, EXCEPT
3) Every year divisible by 400 IS a leap year, EXCEPT
4) (I don't know where the next exception falls, but these first
3 should be good enough for anything since Year 0, at least)

So in essence you apply the above rules to count the number of days in each year
until you get to the target year, then start counting days per month (watch out
for February) until you get to the target month, etc.

This is a simple-minded way to go about it of course, and somewhat less trivial
to code correctly than it probably sounds, but it is good enough for reasonable
time spans. Low-level system utilities which must do this sort of calculation
as quickly as possible use highly optimized code and every mathematical trick in
the book.

HTH,
-rick-

Pohihihi wrote:
ah, again I did.

I should have said I want to know how to make my own DateTime kind of
function. Just want to know the math behind.
"Rick Lones" <Wr******@YcharterZ.net> wrote in message
news:xs*****************@fe03.lga...
Pohihihi wrote:
where can I get code/process/algorithm/or any kind of example to
calculate what day of the week (or month or year) is say 5th of sep in
1767.


DateTime dt = new DateTime(1767,9,5);
string s = dt.DayOfWeek.ToString();

HT H,
-rick-


Nov 17 '05 #4
It is worth mentioning that you also need to take into account the change to
the Gregorian calendar http://www.furrfu.com/magpies/cal_gregorian.html

"Rick Lones" <Wr******@YcharterZ.net> wrote in message
news:Fh*****************@fe03.lga...
Well, given any starting date for which you know the day of week, you
would work with the difference in days modulo 7. But of course the real
issue is how to count up that difference in days. All you really need is
the leap year rules:

1) Every year divisible by 4 is a leap year, EXCEPT
2) Every year divisible by 100 is NOT a leap year, EXCEPT
3) Every year divisible by 400 IS a leap year, EXCEPT
4) (I don't know where the next exception falls, but these
first
3 should be good enough for anything since Year 0, at
least)

So in essence you apply the above rules to count the number of days in
each year until you get to the target year, then start counting days per
month (watch out for February) until you get to the target month, etc.

This is a simple-minded way to go about it of course, and somewhat less
trivial to code correctly than it probably sounds, but it is good enough
for reasonable time spans. Low-level system utilities which must do this
sort of calculation as quickly as possible use highly optimized code and
every mathematical trick in the book.

HTH,
-rick-

Pohihihi wrote:
ah, again I did.

I should have said I want to know how to make my own DateTime kind of
function. Just want to know the math behind.
"Rick Lones" <Wr******@YcharterZ.net> wrote in message
news:xs*****************@fe03.lga...
Pohihihi wrote:

where can I get code/process/algorithm/or any kind of example to
calculate what day of the week (or month or year) is say 5th of sep in
1767.

DateTime dt = new DateTime(1767,9,5);
string s = dt.DayOfWeek.ToString();

HT H,
-rick-



Nov 17 '05 #5
The most common algorithm is known as "Zeller's Congruence", and you can
find more about it here: http://www.merlyn.demon.co.uk/zeller-c.htm#OZC

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
"Pohihihi" <po******@hotmail.com> wrote in message
news:u9**************@TK2MSFTNGP14.phx.gbl...
where can I get code/process/algorithm/or any kind of example to calculate
what day of the week (or month or year) is say 5th of sep in 1767.

Nov 18 '05 #6
This is in C++, but should get you started:

http://www.geocities.com/jeff_louie/date.htm

Regards,
Jeff

*** Sent via Developersdex http://www.developersdex.com ***
Nov 18 '05 #7
Thank you everyone for the pointers. It will surely start me in the right
direction.

"Pohihihi" <po******@hotmail.com> wrote in message
news:u9**************@TK2MSFTNGP14.phx.gbl...
where can I get code/process/algorithm/or any kind of example to calculate
what day of the week (or month or year) is say 5th of sep in 1767.

Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jack Smith | last post by:
Hello, any help appreciated with following problem. I figured out the algorithm (I think), just having trouble proving it is optimal. Suppose we are given n tasks each of which takes 1 unit...
16
by: cody | last post by:
I have to write an algorithm with must ensure that objects are put in buckets (which are always 4 in size). The objects have two properties: A and B. It is not allowed that in a bucket are objects...
10
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement,...
32
by: Cmorriskuerten | last post by:
HI, is this is this solution to test if a number is a prime number or not: /* * Is n a prime number? * Return TRUE (1): n is a prime number * Return FALSE (0): n is a *not* a prime number...
2
by: ben | last post by:
hello, i'm following an algorithm book and am stuck on an early excersise in it, not because of the c programming side of it or even the algorithm side of it, i don't think, but because of maths....
113
by: Bonj | last post by:
I was in need of an encryption algorithm to the following requirements: 1) Must be capable of encrypting strings to a byte array, and decyrpting back again to the same string 2) Must have the same...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
2
by: Julio C. Hernandez Castro | last post by:
Dear all, We have just developped a new block cipher called Raiden, following a Feistel Network structure by means of genetic programming. Our intention now consists on getting as much feedback...
0
by: aruna | last post by:
hey guys i earlier had very valuable responses from you all for base64 encoding algorithm.so thank for that. so now i need your assistance to do a float encoding algorithm. you may wonder why i'm...
1
by: almurph | last post by:
Hi everyone, Concerning the Needleman-Wunsch algorithm (cf. http://en.wikipedia.org/wiki/Needleman-Wunsch_algorithm) I have noticed a possible loop. Inside the algorithm there is an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.