okay I need to know if there is any way to find the difference in days between two java.sql.Date variables? It can also be java.util.Date as well because i convert it to that in my code. [ July 12, 2005: Message edited by: Patrick Mallahan ]
Christopher Elkins
Ranch Hand
Joined: Oct 26, 2004
Posts: 45
posted
0
Use a java.util.Calendar or subclass thereof. It provides that functionality.
Christopher Elkins, SCJP Java 2 Platform
Patrick Mallahan
Ranch Hand
Joined: Apr 22, 2005
Posts: 69
posted
0
what method in calender do you use? and where can i find thereof?
You can then retrieve the day of the year from those calendar objects as an int: int d1 = c1.get(Calendar.DAY_OF_YEAR); int d2 = c2.get(Calendar.DAY_OF_YEAR);
Subtracting one from the other will give you the difference in days between the two dates: int diff = d2 - d1;
This should work as long as the dates are within the same year. A little extra tweaking should make it work across years. Hope that helps.
Yes, the Calendar object is a great way of handling dates. Some methods of the Date object have been deprecated in favor of using the ones provided by the Calendar object
Patrick Mallahan
Ranch Hand
Joined: Apr 22, 2005
Posts: 69
posted
0
wow, it works so good, and its not even difficult to set up, thanks all.