Advertisement
mmayoub

Count days between two dates

Mar 10th, 2023 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | Software | 0 0
  1. public static int countDays(Date date1, Date date2) {
  2. Date startDate, endDate;
  3. int result;
  4.  
  5. if (date1.before(date2))
  6. startDate = date1;
  7. else
  8. startDate = date2;
  9.  
  10. if (date1.after(date2))
  11. endDate = date1;
  12. else
  13. endDate = date2;
  14.  
  15. result = 1;
  16. while (startDate.before(endDate)) {
  17. startDate = startDate.nextDate();
  18. result++;
  19. }
  20. return result;
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement