Results 1 to 4 of 4
  1. #1
    ShaneO is offline Member
    Join Date
    May 2012
    Rep Power

    Red face Date Math with weekends & holidays?

    Good day,

    Is there a way I can determine what date it will be in 5 days (excluding weekends and holidays)?

    If not - what about just weekends? Is there a way to add custom holidays?

    Thank you,

    Java Code:
    		public Date getDteReturnDate() {
    			Calendar c = Calendar.getInstance();
    			if (intWords < 100) {
    				c.add(Calendar.DATE, 5);
                          } else {
    				//TODO Return Error or information screen
    			return c.getTime();
    Last edited by ShaneO; 07-09-2013 at 07:05 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Date Math with weekends & holidays?

    Have you read the API documentation for the Calendar (GregorianCalendar) class? It has all the arithmetic needed for calendar calculations. except holidays; holidays differ per country (or even regions of a country) and can differ each year.

    kind regards,

    Last edited by JosAH; 07-09-2013 at 07:18 PM. Reason: I can't even spell ...
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: Date Math with weekends & holidays?

    Quote Originally Posted by ShaneO View Post
    Is there a way I can determine what date it will be in 5 days (excluding weekends and holidays)?
    What is your actual requirement here? In 5 days the date will be 5 days later, whether the interim time has holidays or not.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Rep Power

    Default Re: Date Math with weekends & holidays?

    He's of course talking about working days, not week days.

    Me - I'd just dumbly iterate from the starting day to the ending day, checking the 'state' of each day along the way. If you have a database of 'invalid' days (holidays, weekend days, ...) you can probably make that less dumb and simply count how many days there are in total and subtract how many discount days there are between those two dates with a simple count query on the database.

Similar Threads

  1. Can't get my date math to work
    By pahiker in forum New To Java
    Replies: 8
    Last Post: 07-13-2010, 02:06 AM
  2. Public Holidays (Australia)
    By oranjeBoven in forum Advanced Java
    Replies: 0
    Last Post: 02-13-2008, 08:14 AM
  3. Date math
    By orchid in forum New To Java
    Replies: 2
    Last Post: 04-18-2007, 07:01 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts