Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Number of days between two dates without the weekend  RSS feed

 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I need help in this code, it give me a wrong result. The inputs are 2 dates and the result is the number of days between these 2 dates without weekend (Friday and Saturday).




Thank you.
 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I don't know enough about your problem to really answer you.  Can it be any two dates? So June 1st 1934 and Februsry 11 2018?  Or is there a range of dates or a set number of days? do you remove all weekends or just the last one?  What range of days do we have to span?

wadha alketbi wrote:Hi

I need help in this code, it give me a wrong result. The inputs are 2 dates and the result is the number of days between these 2 dates without weekend (Friday and Saturday).




Thank you.
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your response, acutely I solve it now
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wadha alketbi wrote:Thank you for your response, acutely I solve it now

It would be great if you could show us your solution.

Also: if you're on version 8, there is a whole new set of classes that allow you to deal with dates and times (and their "differences") much more easily than with Calendar, which (IMO) is probably one of the worst legacy classes in the Java pantheon.

Winston
 
wadha alketbi
Ranch Hand
Posts: 56
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wadha alketbi wrote:

Thanks. Have a cow!

A couple of things that might make it a bit more "generic":

1. Create a separate method for calculating the difference between two Dates in days, eg:and now you can get a "whole number" of days difference with:
  long days = daysBetween(start, end).longValue();

2. Put these methods in a separate utility class (DateUtils?) so that you can re-use them whenever you want.

HIH

Winston
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!