hi everyone,
i need to take year and month as input and generate a calendar for 12months,
i need to rite a jsp page with servlet
can any 1 helpplz
Printable View
hi everyone,
i need to take year and month as input and generate a calendar for 12months,
i need to rite a jsp page with servlet
can any 1 helpplz
Did you Goole it. There should be some mathematical way to find it.
yes i did and cudnt find anything
Ok, here is a way.
d - days of a montheCode:N = d + 2m + [3(m+1)/5] + y + [y/4] - [y/100] + [y/400] + 2
m - moth id(from 1 to 12 respectively)
y - year
Do the calculations and find the N. Keep in mind that to drop the remainder in each [] and only get the whole number. Don't rounding off numbers. Then divide the N by 7. Remainder give the answer, day of the week.
0 - Saturday
1 - Sunday
2 - Monday
3 - Tuesday and so on.
Try it and see.
Ah, made a mistake in my explanation. Here is an example for today(5/5/2008)
After dividing by 7, remainder is 2, means that today is Monday. Yep, it's correct.Code:N = 5 + 2(5) + [3(6)/5] + 2008 + [2008/4] - [2008/100] + [2008/400] + 2
N = 5 + 10 + 3 + 2008 + 502 - 20 + 5 + 2
N = 2515
d is not the number of days of the month. Days spending up to date which we want to processing.
Did you get it?
im trying to write in servlet and get in jsp
The way Eranga explain it is correct. except you have to account for leap years. which you do with an array I forget the exact table.
hey Eranga
when u add up N=2501
Is it.
Where I'm going wrong pal. Can you pointed it for me?Code:N = 1 + 2(1) + [3(2)/5] + 2008 + [2008/4] - [2008/100] + [2008/400] + 2
N = 1 + 2 + 1 + 2008 + 502 - 20 + 5 + 2
N = 5 + 2008 + 502 - 20 + 7
N = 2510 - 20 + 12
N = 2502
let me try again
Linky
Try this on for size.
Go it. I've miss a very important rule there. Really sorry about. Still I remembering this and let you know, because I do those things few years back when I'm in the university for maths.
You have to use numbers 13 and 14 for the months of January and February, with the previous year. In our discussion,
1/1/2008 should be 1/13/2007.
Lets try it.
You get the correct answer there.Code:N = 1 + 2(13) + [3(14)/5] + 2007 + [2007/4] - [2007/100] + [2007/400] + 2
N = 1 + 26 + 8 + 2007 + 501 - 20 + 5 + 2
N = 2530
Lets do another example, for 20/2/2008. So the date should be 20/14/2007
Yep, I'm correct. Give the correct answer here too.Code:N = 20 + 2(14) + [3(15)/5] + 2007 + [2007/4] - [2007/100] + [2007/400] + 2
N = 20 + 28 + 9 + 2007 + 501 - 20 + 5 + 2
N = 2552
Keep in mind that, rule only valid for January and February.
yep i got it and did in servlet
when i was searching i got the same formula
any ways thnks very much
its a nice formula though
I think you can just use the Gregorian calendar I think also.
No matter what calender you used, my formula is working. We have used in few projects that formula, when I'm in the University.
Hey veena, no need to edit your post time to time. If you expecting the answer in different approaches please let it to others. Because later someone read your thread, really confused. :)