• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Number of days between two dates without the weekend

 
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 1093
29
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 66
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your response, acutely I solve it now
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 66
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic