Getting the Week count for the Two date range

G

George

Hi,
I am using a date application. Here I am giving a date as input
and the total week count is the output.The week count should be
calculated from Sunday to Saturday as one week count. Is there any
method in java to get this format of week count.

Cheers!

George
 
F

fred.l.kleinschmidt

Hi,
I am using a date application. Here I am giving a date as input
and the total week count is the output.The week count should be
calculated from Sunday to Saturday as one week count. Is there any
method in java to get this format of week count.

Not enough information.
Suppose d1 is a Monday, and d2 is Friday 11 days later. What is the "week count" of this range?
 
L

Lew

fred.l.kl...@ said:
Not enough information.
Suppose d1 is a Monday, and d2 is Friday 11 days later. What is the "week count" of this range?

Once you have your spec down more precisely, look perhaps to the 'java.util.Calendar' class for ways to implement it. It will require piecemeal assembly of the exact algorithm you want, using things like
<http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#get(int)>
<http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#WEEK_OF_YEAR>
<http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#add(int, int)>
<http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#setFirstDayOfWeek(int)>
<http://docs.oracle.com/javase/7/docs/api/java/util/Calendar.html#setMinimalDaysInFirstWeek(int)>
etc.

If all that is too primitive, the Joda Time initiative is very promising:

<http://joda-time.sourceforge.net/>
 
G

George

Not enough information.
Suppose d1 is a Monday, and d2 is Friday 11 days later. What is the "weekcount" of this range?

the week count is 2

monday to saturday as 1 week count and sunday to friday another week
count.

In my case week count should start from Sunday to Saturday.
 
R

Roedy Green

I am using a date application. Here I am giving a date as input
and the total week count is the output.The week count should be
calculated from Sunday to Saturday as one week count. Is there any
method in java to get this format of week count.

the trick will be getting a day number since 1970, and dividing by 7
and taking a modus 7.

There are various ways to calculate it. One might be subtract the
two day numbers and divide by 7, or add 6 first and divide by 7 for a
covered quotient.
--
Roedy Green Canadian Mind Products
http://mindprod.com
When you were a child, if you did your own experiment
to see if it was better to put to cocoa into your cup first
or the hot milk first, then you likely have the programmer gene..
 
S

Stefan Ram

George said:
monday to saturday as 1 week count and sunday to friday
another week count.

Which only shows that a function cannot be defined by its
value for a single point (that is, by an example).

What we would like to know: Given a date Y-M-D and
a date y-m-d what is the week count of ( Y-M-D, y-m-d )?

»Software development and writing are both the art of
knowing what you're going to do, and then lucidly
expressing your ideas.«

http://praisecurseandrecurse.blogspot.com/2007/03/english-majors-as-programmers.html
 
G

George

the trick will be getting a day number since 1970, and dividing by 7
and taking a modus 7.

There are various ways to calculate it.  One might be  subtract the
two day numbers and divide by 7, or add 6 first and divide by 7 for a
covered quotient.
--
Roedy Green Canadian Mind Productshttp://mindprod.com
When you were a child, if you did your own experiment
to see if it was better to put to cocoa into your cup first
or the hot milk first, then you likely have the programmer gene..

Thank You!

Cheers!

George
 
R

Roedy Green

I am using a date application. Here I am giving a date as input
and the total week count is the output.The week count should be
calculated from Sunday to Saturday as one week count. Is there any
method in java to get this format of week count.

There are so many ways of computing such things, what you really want
is a sequential day number. Then you do some subtractions and modular
% and /. To get the day number, see
http://mindprod.com/products1.htm#BIGDATE
--
Roedy Green Canadian Mind Products
http://mindprod.com
Programmers love to create simplified replacements for HTML.
They forget that the simplest language is the one you
already know. They also forget that their simple little
markup language will bit by bit become even more convoluted
and complicated than HTML because of the unplanned way it grows.
..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top