Originally posted by miguel lisboa:
Wouldn't that only work as long as the two dates are in the same year? If you set it up like this:
String sData1 = "31/12/2004";
String sData2 = "1/1/2005";
You'd get 364 instead of 1, wouldn't you?
One way to do it, as long as your dates are both after 1/1/1970, is to convert your strings to Date objects, using either DateFormat or SimpleDateFormat like Miguel did. Then use the getTime() method on those dates to get their values in milliseconds. Subtract the two, then divide the result by 86400000 (milliseconds in a day).
- Jeff