I get date from in format "Nov 4 2006 2:36PM" from stored procedure in sql server.I want to calculate the difference in minutes between 2 dates. Is any function available in java which suited my need or i have to write my own function. Thanks
Hi Dmay, I have also face this problem earlier in my project. As per best of my knowledge there is no function provided in Java for date difference. You have to manually calculate this. [ November 04, 2006: Message edited by: Nitin Jain ]
cal.get(Calendar.MINUTE) cannot be used to get the number of minutes between two Dates except in very limited circumstances, i.e when the Dates are less than 1 hour apart, and therefore it won't be useful to the op. [ November 04, 2006: Message edited by: sven studde ]
Calculating the difference in minutes between two Date objects is very easy. You just call getTime() on both Date objects (which returns the Date as a long variable that contains the number of milliseconds since January 1, 1970) and you subtract the values. That gives you the difference between the Date objects in milliseconds. One minute contains 60 times 1000 milliseconds, so you divide the number by 60,000.
[ November 06, 2006: Message edited by: Jesper Young ]