Number of months covered between two dates

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Number of months covered between two dates

Ludwig Magnusson-2
Hello!
First of all thanks for a great api.
Sometimes, it can be a bit hard to grasp though.
I’m trying to figure out how to get the number of months covered between two dates.
What I mean is:
If the start date is january 1 and the end date is january 31 of the same year, the number of months covered is 1 since the interval only “touches” january. However, if the start date is january 31 and the end date is february 2, then the number of months is 2. The interval “touches” both january and february.
 
I have tried to use the Months class but when the start date is 2012-01-01 and the end date is 2012-12-31 i only get 11 months where I would like 12. I guess this is because the period is from the beginning of january 1 to the beginning of december 31, not quite a span of 12 months.
 
Is the functionallity for what I want?
 
/Ludwig

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Number of months covered between two dates

jodastephen
You probably want to call plusDays(1) on the end date before passing
it to Months.between.
Stephen

On 3 November 2011 09:50, Ludwig Magnusson <[hidden email]> wrote:

> Hello!
> First of all thanks for a great api.
> Sometimes, it can be a bit hard to grasp though.
> I’m trying to figure out how to get the number of months covered between two
> dates.
> What I mean is:
> If the start date is january 1 and the end date is january 31 of the same
> year, the number of months covered is 1 since the interval only “touches”
> january. However, if the start date is january 31 and the end date is
> february 2, then the number of months is 2. The interval “touches” both
> january and february.
>
> I have tried to use the Months class but when the start date is 2012-01-01
> and the end date is 2012-12-31 i only get 11 months where I would like 12. I
> guess this is because the period is from the beginning of january 1 to the
> beginning of december 31, not quite a span of 12 months.
>
> Is the functionallity for what I want?
>
> /Ludwig
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Save $700 by Nov 18
> Register now
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
>

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Number of months covered between two dates

Ludwig Magnusson-2
It doesn't really cover all the cases I mentioned, but it seems to work for
in the situation I'm in.
Thanks

-----Ursprungligt meddelande-----
From: Stephen Colebourne
Sent: Thursday, November 03, 2011 11:29 AM
To: Discussion of the Joda project
Subject: Re: [Joda-interest] Number of months covered between two dates

You probably want to call plusDays(1) on the end date before passing
it to Months.between.
Stephen

On 3 November 2011 09:50, Ludwig Magnusson <[hidden email]> wrote:

> Hello!
> First of all thanks for a great api.
> Sometimes, it can be a bit hard to grasp though.
> I’m trying to figure out how to get the number of months covered between
> two
> dates.
> What I mean is:
> If the start date is january 1 and the end date is january 31 of the same
> year, the number of months covered is 1 since the interval only “touches”
> january. However, if the start date is january 31 and the end date is
> february 2, then the number of months is 2. The interval “touches” both
> january and february.
>
> I have tried to use the Months class but when the start date is 2012-01-01
> and the end date is 2012-12-31 i only get 11 months where I would like 12.
> I
> guess this is because the period is from the beginning of january 1 to the
> beginning of december 31, not quite a span of 12 months.
>
> Is the functionallity for what I want?
>
> /Ludwig
> ------------------------------------------------------------------------------
> RSA(R) Conference 2012
> Save $700 by Nov 18
> Register now
> http://p.sf.net/sfu/rsa-sfdev2dev1
> _______________________________________________
> Joda-interest mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
>

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest 


------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Number of months covered between two dates

Mark Carroll
On 11/03/2011 07:40 AM, Ludwig Magnusson wrote:
> It doesn't really cover all the cases I mentioned, but it seems to work for
> in the situation I'm in.

For how many months were "touched", you can set the start date to the
first day of the month and the end date to the last day of the month
before adding the extra day to the end date and finding the months in
between. The field methods like withMaxFieldValue or whatever it's
called are useful for things like "last day of the month". I hope that
helps.

Or maybe it works to set both the start and end date to the first of the
month, check how many months are between them, and add 1 to the answer;
I'd have to think about it more than I have time for right now. (-:

Mark

--
Mark Carroll
Software Engineer
[hidden email]
http://www.vecna.com/

Cambridge Research Laboratory
Vecna Technologies, Inc.
36 Cambridge Park Drive
Cambridge, MA 02140
Phone: (617) 864-0636
Fax: (617) 864-0638

Better Technology, Better World (TM)

The contents of this message may be privileged and confidential.
Therefore, if this message has been received in error, please delete it
without reading it. Your receipt of this message is not intended to
waive any applicable privilege. Please do not disseminate this message
without the permission of the author.

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Number of months covered between two dates

Ludwig Magnusson-2
Thanks for the suggestion.
It seems that there is no one method in any class for the functionallity I
want. With that known, I can probably find a solution like this one or like
Stephens.
I'll see what works for me and my project =)
/Ludwig

-----Ursprungligt meddelande-----
From: Mark Carroll
Sent: Thursday, November 03, 2011 12:50 PM
To: Discussion of the Joda project
Subject: Re: [Joda-interest] Number of months covered between two dates

On 11/03/2011 07:40 AM, Ludwig Magnusson wrote:
> It doesn't really cover all the cases I mentioned, but it seems to work
> for
> in the situation I'm in.

For how many months were "touched", you can set the start date to the
first day of the month and the end date to the last day of the month
before adding the extra day to the end date and finding the months in
between. The field methods like withMaxFieldValue or whatever it's
called are useful for things like "last day of the month". I hope that
helps.

Or maybe it works to set both the start and end date to the first of the
month, check how many months are between them, and add 1 to the answer;
I'd have to think about it more than I have time for right now. (-:

Mark

--
Mark Carroll
Software Engineer
[hidden email]
http://www.vecna.com/

Cambridge Research Laboratory
Vecna Technologies, Inc.
36 Cambridge Park Drive
Cambridge, MA 02140
Phone: (617) 864-0636
Fax: (617) 864-0638

Better Technology, Better World (TM)

The contents of this message may be privileged and confidential.
Therefore, if this message has been received in error, please delete it
without reading it. Your receipt of this message is not intended to
waive any applicable privilege. Please do not disseminate this message
without the permission of the author.

------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest 


------------------------------------------------------------------------------
RSA(R) Conference 2012
Save $700 by Nov 18
Register now
http://p.sf.net/sfu/rsa-sfdev2dev1
_______________________________________________
Joda-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/joda-interest
Loading...