Skip to content

Instantly share code, notes, and snippets.

@dj-amadeous
Created October 23, 2016 02:14
Show Gist options
  • Save dj-amadeous/ca3dfc39bdecdf434e59f60775831d32 to your computer and use it in GitHub Desktop.
Save dj-amadeous/ca3dfc39bdecdf434e59f60775831d32 to your computer and use it in GitHub Desktop.
how do I add 365 to each year without messing up the # of days?
if (yearDiff == 0) // Both dates in same year
{
monthsBetween = mm2 - mm1; // if year is same, day2 must be after day1
if (monthValid && (monthsBetween == 0))
{
daysBetween = dd2 - dd1;
}
else if (monthValid)
{
daysBetween = daysToEndOfMonth(dd1,mm1);
daysBetween = daysOfMonth(daysBetween, mm1+1, mm2);
daysBetween += dd2;
}
}
else if ((yearDiff > 0) && (monthValid)) // Year2 is after Year 1
{
System.out.println();
daysBetween = daysToEndOfMonth(dd1,mm1);
daysBetween = daysOfMonth(daysBetween,mm1+1,12+1);
daysBetween = daysOfMonth(daysBetween,1,mm2);
daysBetween += dd2;
daysBetween += yearDiff*365;// *-* add in 365 days for each year inbetween yyyy1 and yyyy2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment