cancel
Showing results for 
Search instead for 
Did you mean: 

difference between two dates

Former Member
0 Kudos

hai all,

i have a button clicking on which i need to calculate if the difference between the current date and another date is > 7 (week).plz hel me with codings.

Thanks n Regards

Sharanya.R

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Pl go through this

http://www.jguru.com/forums/view.jsp?EID=489372

Regards

Ayyapparaj

Former Member
0 Kudos

Hi,

Try this code..

Calendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25);

Calendar newyears = new GregorianCalendar(1999, Calendar.JANUARY, 1);

// Determine which is earlier

boolean b = xmas.after(newyears); // false

b = xmas.before(newyears); // true

// Get difference in milliseconds

long diffMillis = newyears.getTimeInMillis() - xmas.getTimeInMillis();

// Get difference in seconds

long diffSecs = diffMillis / (1000); // 604800

// Get difference in minutes

long diffMins = diffMillis / (60 * 1000); // 10080

// Get difference in hours

long diffHours = diffMillis / (60 * 60 * 1000); // 168

// Get difference in days

long diffDays = diffMillis / (24 * 60 * 60 * 1000); // 7

System.out.println("Difference =" + diffDays);

--

Shyam