# check the sunday and saturday from a given date range

• 07-20-2010, 06:43 AM
harsha.udupa2008
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
• 07-20-2010, 07:06 AM
arun9683
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..
• 07-20-2010, 07:35 AM
harsha.udupa2008
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
• 07-20-2010, 07:52 AM
arun9683
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..

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");     }   } }```
• 07-20-2010, 07:57 AM
arun9683

Calculating the Number of Days Between Two Dates in java - Q&A
• 07-20-2010, 08:22 AM
Quote:

Originally Posted by arun9683
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..

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?