programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Jeanne Boyarsky
• Ron McLeod
• Paul Clapham
• Liutauras Vilda
Sheriffs:
• paul wheaton
• Rob Spoor
• Devaka Cooray
Saloon Keepers:
• Stephan van Hulst
• Tim Holloway
• Carey Brown
• Frits Walraven
• Tim Moores
Bartenders:
• Mikalai Zaikin

# How to obtain week of year for any given date

Greenhorn
Posts: 2
• Number of slices to send:
Optional 'thank-you' note:
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.
Thanks,
sunsel

Ranch Hand
Posts: 118
• Number of slices to send:
Optional 'thank-you' note:
Can you post some code please?
/Peter

Ranch Hand
Posts: 2545
• Number of slices to send:
Optional 'thank-you' note:
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.

Sheriff
Posts: 9109
12
• Number of slices to send:
Optional 'thank-you' note:
If you know the "day" of the year, you can divide by 7.

Ranch Hand
Posts: 84
• Number of slices to send:
Optional 'thank-you' note:

Maybe what you're after.
Usage: java TestDate 06/08/1982
[ January 04, 2003: Message edited by: Cory Wilkerson ]

John Lee
Ranch Hand
Posts: 2545
• Number of slices to send:
Optional 'thank-you' note:
I am just guessing:
Will it work if you use:
Calender c = new Calender() ;
to create Calender object.

Ranch Hand
Posts: 71
• Number of slices to send:
Optional 'thank-you' note:
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.

Wanderer
Posts: 18671
• Number of slices to send:
Optional 'thank-you' note:
Perhaps you guys should try compiling

to see what happens.

John Lee
Ranch Hand
Posts: 2545
• Number of slices to send:
Optional 'thank-you' note:
Hi:

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

I thought this is the problem.

Nayanjyoti Talukdar
Ranch Hand
Posts: 71
• Number of slices to send:
Optional 'thank-you' note:
Hi,
I'm sorry. I missed out...
Calendar is an abstract class, so we can't instantiate that.
-------------
Nayan.

Nayanjyoti Talukdar
Ranch Hand
Posts: 71
• Number of slices to send:
Optional 'thank-you' note:
Hi,
Just check this out..

---------
Nayan

John Lee
Ranch Hand
Posts: 2545
• Number of slices to send:
Optional 'thank-you' note:
Hi:

Now compare these two codes, could this be the reason?

Ranch Hand
Posts: 1179
• Number of slices to send:
Optional 'thank-you' note:
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 ]

 With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.