Forums Register Login

How to obtain week of year for any given date

+Pie Number of slices to send: Send
Hi,
I am trying to find a way to obtain the week of the year for any user entered date. but each time the week of the year corresponding to todays date.
Please help.
Thanks,
sunsel
+Pie Number of slices to send: Send
Can you post some code please?
/Peter
+Pie Number of slices to send: Send
It depends on how you define the week of the year. Will the first partial week be counted as first week?
You can calculate Julian date (how many days from January 1 to that day), then use mode(days, 7) function to find out how many weeks passed. Then again, it depends on the definition.
+Pie Number of slices to send: Send
If you know the "day" of the year, you can divide by 7.
+Pie Number of slices to send: Send

Maybe what you're after.
Usage: java TestDate 06/08/1982
[ January 04, 2003: Message edited by: Cory Wilkerson ]
+Pie Number of slices to send: Send
I am just guessing:
Will it work if you use:
Calender c = new Calender() ;
to create Calender object.
+Pie Number of slices to send: Send
Hi,
We can create object using:
Calendar cal = new Calendar();
But the problem, we'll be facing here is that we can't use the fields and methods of class GregorianCalendar which has all the important methods of date format.
-------------
Nayan.
+Pie Number of slices to send: Send
Perhaps you guys should try compiling

to see what happens.
+Pie Number of slices to send: Send
Hi:


but each time the week of the year corresponding to todays date.


I thought this is the problem.
+Pie Number of slices to send: Send
Hi,
I'm sorry. I missed out...
Calendar is an abstract class, so we can't instantiate that.
-------------
Nayan.
+Pie Number of slices to send: Send
Hi,
Just check this out..

---------
Nayan
+Pie Number of slices to send: Send
Hi:



Now compare these two codes, could this be the reason?
+Pie Number of slices to send: Send
NOTE...
when you are using 'c.set(Calendar.MONTH, 5);' you need to subtract 1 from the month, because the first month has the value 0.
Rene
[ January 08, 2003: Message edited by: Rene Larsen ]
It's a pleasure to see superheros taking such an interest in science. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2107 times.
Similar Threads
Get WeekStart Date & End date by Week Number in java
date problem
Calculate Fiscal year
To find week of the year for any given date
daysOfWeek function implementation
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:17:56.