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

    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();
    			c.setTime(dteRequestDate);
    			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 08:05 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    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,

    Jos
    Last edited by JosAH; 07-09-2013 at 08:18 PM. Reason: I can't even spell ...
    cenosillicaphobia: the fear for an empty beer glass

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

    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.

    Regards,
    Jim
    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
    Location
    Netherlands
    Posts
    4,277
    Rep Power
    6

    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, 03:06 AM
  2. Public Holidays (Australia)
    By oranjeBoven in forum Advanced Java
    Replies: 0
    Last Post: 02-13-2008, 09:14 AM
  3. Date math
    By orchid in forum New To Java
    Replies: 2
    Last Post: 04-18-2007, 08: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
  •