Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing Timestamps in Java to get difference in days [duplicate]

Tags:

timestamp

I'm retrieving two timestamps from a database (check_in and check_out). I need to compare the two to find out how many days have passed between the two timestamps. How can this be done in Java?

like image 782
Daal Avatar asked Apr 20 '26 04:04

Daal


1 Answers

Just subtract check_out and check_in, and convert from whatever units you're in to days. Something like

//pseudo-code
diff_in_millis = Absolute Value Of ( check_out - check_in ) ;
diff_in_days = diff_in_millis / (1000  * 60 * 60 * 24);
like image 172
Amir Afghani Avatar answered Apr 29 '26 23:04

Amir Afghani