Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare if two dates are within same week in android

Tags:

java

date

android

I have two dates.Got them from something like......

Calendar c=Calendar.getInstance();
year=c.get(c.YEAR);
month=c.get(c.MONTH);
month++;
date=c.get(c.DATE);

and other date is broken into date2,month2

Now I want to see if both of them are in the same week.

It's possible through lots of calculation and logic.Problem occurs when 1st date is suppose 03 March and 2nd date is 28Feb. Both of them are in same week but difficult to compare/check that. So I want to know if there is any built in function or any way to compare them easily.Please help..........

like image 338
AtanuCSE Avatar asked Mar 09 '12 20:03

AtanuCSE


People also ask

How do you compare two dates in if condition?

Compare dates if greater than another date with formula 2. Select a blank cell which is corresponding to the first date cell in the Date column such as G2. Then copy and paste formula =IF(A2>$F$2, "YES", "NO") into the Formula Bar and press the Enter key.


1 Answers

I ended up using

date1.with(previousOrSame(MONDAY)).equals(date2.with(previousOrSame(MONDAY)))

assuming that weeks start on Monday.

like image 51
Jan-David Salchow Avatar answered Nov 03 '22 01:11

Jan-David Salchow