Suppose I have : Employee model which has startDate as its property variable and Promotion model has promotionDate. I want to find out for how long employee has worked until his promotion for which I have to find difference between promotionDate and startDate. If I get startDate as employee.getStartDate() and promotionDate as promotion.getPromotionDate, how can I find difference in years months and days for any dates,
Any help would be really appreciated.
UPDATE : I SOLVED PROBLEM AS BELOW
String startDate = "2018-01-01";
String promotionDate = "2019-11-08";
LocalDate sdate = LocalDate.parse(startDate);
LocalDate pdate = LocalDate.parse(promotionDate);
LocalDate ssdate = LocalDate.of(sdate.getYear(), sdate.getMonth(), sdate.getDayOfMonth());
LocalDate ppdate = LocalDate.of(pdate.getYear(), pdate.getMonth(), pdate.getDayOfMonth());
Period period = Period.between(ssdate, ppdate);
System.out.println("Difference: " + period.getYears() + " years "
+ period.getMonths() + " months "
+ period.getDays() + " days ");
Thank you.