Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Default check the sunday and saturday from a given date range

    Hi all,

    i have a requirement that from a given date range i should count the number of days and i should not count the sunday and saturday from the date range. please help me on this. and i want to check the start date should be less than end date. please help me on this...... if you have any code please share it with me. i would be really helpfull.

    regards,
    harsha

  2. #2
    arun9683 is offline Member
    Join Date
    Jun 2010
    Location
    Bangalore,India
    Posts
    70
    Rep Power
    0

    Default

    Write a method which takes fromdate and todate as arguements and by the help of Calendar class you can count the days without including saturday and sunday..
    Arun K R,Bangalore,India
    :)

  3. #3
    Join Date
    Apr 2010
    Posts
    19
    Rep Power
    0

    Default check the sunday and saturday from a given date range

    hi arun,

    if you know the code can you please share with me please.... harsha.udupa2002@gmail.com is my email id.

    regards,
    harsha

  4. #4
    arun9683 is offline Member
    Join Date
    Jun 2010
    Location
    Bangalore,India
    Posts
    70
    Rep Power
    0

    Default

    Find the number of days between the dates ,
    Find the number of saturdays and sundays in between
    The difference will give you the exact number of days..

    Refer the following code which will help you in writing the method..

    Java Code:
    import java.util.*;
    
    public class FirstDayOfWeek{
      public static void main(String[] args) {
        GregorianCalendar gcal = new GregorianCalendar();
        int week = gcal.getActualMaximum(Calendar.DAY_OF_WEEK);
        System.out.println("Day of week: " + week);
        int first = gcal.getFirstDayOfWeek() ;
        switch(first){
          case 1:
            System.out.println("Sunday");
          break;
          case 2:
            System.out.println("Monday");
          case 3:
            System.out.println("Tuesday");
          case 4:
            System.out.println("Wednesday");
          case 5:
            System.out.println("Thrusday");
          case 6:
            System.out.println("Friday");
          case 7:
            System.out.println("Saturday");
        }
      }
    }
    Arun K R,Bangalore,India
    :)

  5. #5
    arun9683 is offline Member
    Join Date
    Jun 2010
    Location
    Bangalore,India
    Posts
    70
    Rep Power
    0

    Default

    Refer the following link which will help you

    Calculating the Number of Days Between Two Dates in java - Q&A
    Arun K R,Bangalore,India
    :)

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Quote Originally Posted by arun9683 View Post
    Find the number of days between the dates ,
    Find the number of saturdays and sundays in between
    The difference will give you the exact number of days..

    Refer the following code which will help you in writing the method..

    Java Code:
    import java.util.*;
    
    public class FirstDayOfWeek{
      public static void main(String[] args) {
        GregorianCalendar gcal = new GregorianCalendar();
        int week = gcal.getActualMaximum(Calendar.DAY_OF_WEEK);
        System.out.println("Day of week: " + week);
        int first = gcal.getFirstDayOfWeek() ;
        switch(first){
          case 1:
            System.out.println("Sunday");
          break;
          case 2:
            System.out.println("Monday");
          case 3:
            System.out.println("Tuesday");
          case 4:
            System.out.println("Wednesday");
          case 5:
            System.out.println("Thrusday");
          case 6:
            System.out.println("Friday");
          case 7:
            System.out.println("Saturday");
        }
      }
    }
    And what happens if those constant values change? You should be using Calendar.SUNDAY, not "1". And why do the rest not break?

Similar Threads

  1. jField date range
    By JavaTrouble in forum New To Java
    Replies: 5
    Last Post: 05-25-2010, 04:40 AM
  2. Replies: 3
    Last Post: 01-27-2010, 06:12 PM
  3. Compare date input to database with current date
    By hungleon88 in forum Advanced Java
    Replies: 2
    Last Post: 11-25-2008, 08:10 AM
  4. Tech Career Fair - eHarmony - Saturday - Sept 27th
    By Volt Recruiter in forum Jobs Offered
    Replies: 0
    Last Post: 09-25-2008, 12:49 AM
  5. Creating a Gregorian Calendar using a Date object gives date - 1
    By prachi_goliwadekar in forum New To Java
    Replies: 1
    Last Post: 05-08-2008, 08:32 PM

Posting Permissions

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