Hi,
I want to get days, weeks, months and years between two dates(moments). The
API offers this functionality, but it's not working as I expected. My first
try was: 

return Days.daysBetween(lastUpdate,currentUpdate).getDays();

I think it returns full days between two moments. If a have 2012/05/27
8:00PM as "lastUpdate" and 2012/05/28 2:00AM as "currentUpdate" the function
returns 0. I did a little "trick" that worked for days and weeks:

DateTime initialMomentOfDay = new DateTime(lastUpdate.getYear(),
lastUpdate.getMonthOfYear(), lastUpdate.getDayOfMonth(), 0, 0);
return Days.daysBetween(initialMomentOfDay,currentUpdate).getDays();

But when it comes to Months it doesn't work even with the "trick". The code
I used was:

DateTime initialMomentOfMonth = new DateTime(lastUpdate.getYear(),
lastUpdate.getMonthOfYear(), 1, 0, 0);
return Months.monthsBetween(initialMomentOfMonth,
currentUpdate).getMonths();

When lastUpdate = new DateTime(2000, 1, 31, 23, 59)
And currentUpdate = new DateTime(2000, 2, 1, 0, 0)
It returns 0 and should return 1.

Cheers,
Joao Neto

--
View this message in context: 
http://joda-interest.219941.n2.nabble.com/Months-between-dates-tp7572425.html
Sent from the Joda-Interest mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to