Worksheet 6
Worksheet 6
Session 2020-2021
Round 10
Class : XI
Worksheet 6
Question:
Write a program to accept 2 dates in the string
format dd/mm/yyyy and find the difference in days
between the 2 dates.
Example:
INPUT:
Date 1 : 20/12/2012
Date 2 : 11/02/2013
Program Code :
// The class Date_Difference inputs 2 dates and finds
the difference between them
import java.util.*;
class Date_Difference
{
int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
//function for checking for Leap Year
int isLeap(int y)
{
if((y%400==0) || ((y%100!=0)&&(y%4==0)))
return 29;
else
return 28;
}
if(ob.dateValidate(d1,m1,y1)==true &&
ob.dateValidate(d2,m2,y2)==true)
{
int a=ob.dayno(d1,m1,y1);
int b=ob.dayno(d2,m2,y2);
System.out.print("Output : Difference =
"+Math.abs(a-b)+" days.");
}
else
System.out.println("Invalid Date");
}
}