How to count how many days of a certain type (Monday, Friday etc.) exist between two dates?

Asked

Viewed 86 times

2

How do I know how many weekdays of specific types (for example, only Mondays, Tuesdays and Wednesdays) exist between two dates in Java?

For example, from date 01/12 to 30/12, how many segundas, terças e quartas exist among them?

  • Using a lib with for example joda-time, you can do as in this post here, https://stackoverflow.com/questions/3802893/number-of-days-between-two-dates-in-joda-time

  • You want to count the days between two dates, but ignoring certain days of the week in the count, would be this?

  • He wants to count how many "Mondays, Tuesdays and Wednesdays" there are from a date D to a date D+N.

  • that, I want to count how many Mondays, Tuesdays and Wednesdays exist from an X date to a Y date

  • @LR10, the link you passed talks only about counting days between two dates, without taking into account the detail I mentioned, (I edited my reply)...

  • @Felipe.rce See if my edition agrees with what you’re wanting.

  • See this example in Ideone @Felipe.rce. Using only Java.

  • @Gustavocinque is exactly what I wanted!

  • Localdate startDate = new Localdate(2017, 11, 01); Localdate endDate = new Localdate(2017, 11, 30) Days days = Days.daysBetween(startDate, endDate). getDays() ;

  • You can do a for in days and take getDayOfWeek() for example and count the days. It’s a suggestion. As here https://stackoverflow.com/questions/15338196/joda-time-get-week-days

  • That’s right @LR10, came to see the example I put?

  • I’m waiting to reopen (I don’t know why they closed, since it was edited before it was closed) so I can accept the answer

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.