Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Getting the Week count for the Two date range (http://www.velocityreviews.com/forums/t945359-getting-the-week-count-for-the-two-date-range.html)

George 04-13-2012 03:04 PM

Getting the Week count for the Two date range
 
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

fred.l.kleinschmidt@gmail.com 04-13-2012 03:14 PM

Re: Getting the Week count for the Two date range
 
On Friday, April 13, 2012 8:04:08 AM UTC-7, George wrote:
> 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?

Lew 04-13-2012 06:10 PM

Re: Getting the Week count for the Two date range
 
fred.l.kl...@ wrote:
> George wrote:
>> 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?


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...r.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/>

--
Lew

George 04-14-2012 10:29 AM

Re: Getting the Week count for the Two date range
 
On Apr 13, 8:14*pm, fred.l.kleinschm...@gmail.com wrote:
> On Friday, April 13, 2012 8:04:08 AM UTC-7, George wrote:
> > 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 "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.


Roedy Green 04-14-2012 01:49 PM

Re: Getting the Week count for the Two date range
 
On Fri, 13 Apr 2012 08:04:08 -0700 (PDT), George <vijuitech@gmail.com>
wrote, quoted or indirectly quoted someone who said :

> 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..

Stefan Ram 04-14-2012 04:13 PM

Re: Getting the Week count for the Two date range
 
George <vijuitech@gmail.com> writes:
>On Apr 13, 8:14*pm, fred.l.kleinschm...@gmail.com wrote:
>>Suppose d1 is a Monday, and d2 is Friday 11 days later. What
>>is the "week count" of this range?

>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.blogspo...ogrammers.html


George 04-16-2012 04:00 AM

Re: Getting the Week count for the Two date range
 
On Apr 14, 6:49*pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On Fri, 13 Apr 2012 08:04:08 -0700 (PDT), George <vijuit...@gmail.com>
> wrote, quoted or indirectly quoted someone who said :
>
> > * * * 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 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

Roedy Green 04-29-2012 02:49 PM

Re: Getting the Week count for the Two date range
 
On Fri, 13 Apr 2012 08:04:08 -0700 (PDT), George <vijuitech@gmail.com>
wrote, quoted or indirectly quoted someone who said :

> 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.
..

Arne Vajhøj 05-05-2012 11:58 PM

Re: Getting the Week count for the Two date range
 
On 4/29/2012 10:49 AM, Roedy Green wrote:
> On Fri, 13 Apr 2012 08:04:08 -0700 (PDT), George<vijuitech@gmail.com>
> wrote, quoted or indirectly quoted someone who said :
>> 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


Or simpler - just use what comes with Java.

Arne



All times are GMT. The time now is 05:27 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.