Getting the Week count for the Two date range

Discussion in 'Java' started by George, Apr 13, 2012.

  1. George

    George Guest

    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
     
    George, Apr 13, 2012
    #1
    1. Advertising

  2. George

    Guest

    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?
     
    , Apr 13, 2012
    #2
    1. Advertising

  3. George

    Lew Guest

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

    --
    Lew
     
    Lew, Apr 13, 2012
    #3
  4. George

    George Guest

    On Apr 13, 8:14 pm, 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.
     
    George, Apr 14, 2012
    #4
  5. George

    Roedy Green Guest

    On Fri, 13 Apr 2012 08:04:08 -0700 (PDT), George <>
    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..
     
    Roedy Green, Apr 14, 2012
    #5
  6. George

    Stefan Ram Guest

    George <> writes:
    >On Apr 13, 8:14 pm, 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.blogspot.com/2007/03/english-majors-as-programmers.html
     
    Stefan Ram, Apr 14, 2012
    #6
  7. George

    George Guest

    On Apr 14, 6:49 pm, Roedy Green <>
    wrote:
    > On Fri, 13 Apr 2012 08:04:08 -0700 (PDT), George <>
    > 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
     
    George, Apr 16, 2012
    #7
  8. George

    Roedy Green Guest

    On Fri, 13 Apr 2012 08:04:08 -0700 (PDT), George <>
    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.
    ..
     
    Roedy Green, Apr 29, 2012
    #8
  9. George

    Arne Vajhøj Guest

    On 4/29/2012 10:49 AM, Roedy Green wrote:
    > On Fri, 13 Apr 2012 08:04:08 -0700 (PDT), George<>
    > 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
     
    Arne Vajhøj, May 6, 2012
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    1
    Views:
    650
    Matthew Speed
    Nov 8, 2003
  2. Guest
    Replies:
    3
    Views:
    1,885
    Alexandre
    Dec 22, 2003
  3. Matt
    Replies:
    2
    Views:
    573
    Pete Becker
    Nov 8, 2003
  4. Matt
    Replies:
    3
    Views:
    756
    Richard Heathfield
    Nov 8, 2003
  5. Matt
    Replies:
    11
    Views:
    429
    Aaron Bertrand [MVP]
    Nov 8, 2003
Loading...

Share This Page