• 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

how to add 10 working days to date object

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i need help from you,

i want to add 10 working days to current date means don't consider Saturday and Sunday.

For example today is Aug-14 th so i want the date Aug 28th.

Thanks,
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use class Calendar for date arithmetic, especially the add() method of that class. Add days one by one, skipping over Saturdays and Sundays.

Note, are you really sure that "working days" always means Monday to Friday? What about public holidays, should they be regarded as non-working days? And in some countries, the weekend is on Friday and Saturday instead of Saturday and Sunday. I don't know if this is important for your software, but this might be much more complicated in reality than you think.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GregorianCalendar is your friend

In pseudo code
1) Add one day
2) Check if should be ignored (Sat/Sun)
3) If yes repeat from 1
4) If not check if you added 10 valid days
5) Repeat

Beaten by Jesper
 
raghu tammina
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you please provide the code?

Thanks.
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please try writing some code yourself - we're here to help people learn Java, and you'll learn a lot more if you write it yourself then when you let someone else do the work.

To help you get started: Look at the API documentation of class java.util.Calendar. It has an add() method that you can use to add amounts of time. For example:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic