File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to obtain week of year for any given date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to obtain week of year for any given date" Watch "How to obtain week of year for any given date" New topic
Author

How to obtain week of year for any given date

sun sel
Greenhorn

Joined: Jan 03, 2003
Posts: 2
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
Peter Kristensson
Ranch Hand

Joined: Jul 02, 2001
Posts: 118
Can you post some code please?
/Peter
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
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.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
If you know the "day" of the year, you can divide by 7.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Cory Wilkerson
Ranch Hand

Joined: Aug 14, 2001
Posts: 84

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

Joined: Aug 05, 2001
Posts: 2545
I am just guessing:
Will it work if you use:
Calender c = new Calender() ;
to create Calender object.
Nayanjyoti Talukdar
Ranch Hand

Joined: Feb 12, 2002
Posts: 71
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.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Perhaps you guys should try compiling

to see what happens.


"I'm not back." - Bill Harding, Twister
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
Hi:

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

I thought this is the problem.
Nayanjyoti Talukdar
Ranch Hand

Joined: Feb 12, 2002
Posts: 71
Hi,
I'm sorry. I missed out...
Calendar is an abstract class, so we can't instantiate that.
-------------
Nayan.
Nayanjyoti Talukdar
Ranch Hand

Joined: Feb 12, 2002
Posts: 71
Hi,
Just check this out..

---------
Nayan
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
Hi:



Now compare these two codes, could this be the reason?
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

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 ]

Regards, Rene Larsen
Dropbox Invite
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to obtain week of year for any given date