Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Week calculation

Thread view: 
smreddy - 04 Jan 2006 12:08 GMT
Hi,

I want to get a list of week numbers given a date range. Please help me
out.
For ex
Start Date Jan 1 2006
End Date Feb 28 2006
O/p it should give W12006 W22006 ...... W92006

Thanks for the help
Reddy
NullBock - 04 Jan 2006 12:17 GMT
Have you checked out the GregorianCalendar class?

http://java.sun.com/j2se/1.5.0/docs/api/java/util/GregorianCalendar.html

Walter Gildersleeve
Freiburg, Germany

______________________________________________________
http://linkfrog.net
URL Shortening
Free and easy, small and green.
zero - 04 Jan 2006 13:32 GMT
"smreddy" <srinathmreddy@gmail.com> wrote in news:1136376492.722132.46880
@g14g2000cwa.googlegroups.com:

> Hi,
>
[quoted text clipped - 7 lines]
> Thanks for the help
> Reddy

Calendar:get(Calendar.WEEK_OF_YEAR)
Calendar:get(Calendar.YEAR)

Signature

Beware the False Authority Syndrome

Roedy Green - 04 Jan 2006 15:25 GMT
>Start Date Jan 1 2006
>End Date Feb 28 2006
>O/p it should give W12006 W22006 ...... W92006

I have four possible solutions for you all based around BigDate

BigDate is available at http://mindprod.com/products1..html#COMMON11
-------------
BigDate has a method getISOWeekNumber to tell you the ISO week number
of a given day.  But I suspect you have a different definition of week
from ISO. It is defined like this:

Get week number 1 to 53 of the year this date falls in, according to
the rules of ISO standard IS-8601 section 5.5. A week that lies partly
in one year and partly in another is assigned a number in the year in
which most of its days lie. This means that week 1 of any year is the
week that contains 4 January, or equivalently week 1 of any year is
the week that contains the first Thursday in January. Most years have
52 weeks, but years that start on a Thursday and leap years that start
on a Wednesday have 53 weeks. Jan 1 may well be in week 53 of the
previous year! Only defined for dates on or after 1600 Jan 01. You can
find out how many ISO weeks there are per year with new BigDate( year,
12,
31).getISOWeekNumber();

@return week number 1..53, 0 for null or invalid date.
   http://www.pip.dknet.dk/~pip10160/calendar.faq3.txt
Calendar  FAQ
--------
BigDate also has a method getWeekNumber:
defined like this:
Get week number 1 to 53 of the year this date falls in. This does NOT
follow the rules of ISO standard IS-8601 section 5.5. Week 1 is the
first week with any days in the current year. Weeks start on Sunday.
Jan 1 and Dec 31 are always considered part of the current year. Only
defined for dates on or after 1600 Jan 01.
@return week number 1..53, 0 for null or invalid date.
--------------
Bigdate has a method getDayOfWeek that will tell you the day of the
week of any given day (Calendar has a similar feature with the added
complication of deciding a timezone and time of day).
Get day of week for given ordinal. Is it zero-based starting with
Sunday. @return day of week 0=Sunday 1=Monday 2=Tuesday 3=Wednesday
4=Thursday  5=Friday 6=Saturday WARNING: not compatible with
1=Calendar.SUNDAY

-----------
BigDate also has a method toOrdinal that will give you days since
1970.  If you divide that by 7 it will tell you weeks since then, if
you do a % modulus 7 it will tell you the day of week.

I suspect the code you want might then look like this:

int ordinalLast = BigDate.toOrdinal( yyyy2, mm2, dd2 );

int ordinalFirst = BigDate.toOrdinal ( yyyy1, mm1, dd1);

int weekLast =  (ordinallast + fiddle) / 7;

int weekFirst =  (ordinalFirst + fiddle) / 7;

where fiddle is a number chosen to fiddle the results to start weeks
on your preferred day and adjust week 0 to the desired epoch..
Here weeks are numbered from some epoch, not starting over each year.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

smreddy - 06 Jan 2006 08:55 GMT
Thanks for the help.

Smreddy


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.