Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help reg. Days & Dates...

 
Jack Daniel
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey e'body,...
It would be Great if anybody can help me with, how I can find the number of Days between two dates..
like for example # days between 08/07/2003 & 09/15/2003 ..
Which Class do you suggest me to Use.. ( Date,Calendar,DateFormat ??? how?)
Thx a lot for your help.. Appreciate it..
 
Chris Stehno
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way I usually do something like that is...
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date d1 = dateFormat.parse("08/07/2003");
Date d2 = dateFormat.parse("09/15/2003");
long time = d2.getTime() - d1.getTime(); // t dif in ms
// then convert time to the time units you want
 
Jack Daniel
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Chris..
So If you want me to get the # of days ...
I think i'll Go this way :
long time = d2.getTime() - d1.getTime(); // t dif in ms
int days=(int)time/(24*36*100000);
I hope this is going to work always..
Let me know, if by chance i'm going wrong somewhere..
Thx anyway
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic