Calculate date difference

I have two fields in the same SQL 2K server. The fields are identified as arrival_time and departure_time. The fields are date/time fields and contain information as such:

Arrival_Time                         Departure_Time
10/20/2004 08:00:00 AM       10/24/2004 04:00:00 PM

How can I calulate the difference in this information to display the difference in hours?
LVL 12
rcmbAsked:
Who is Participating?
 
CEHJCommented:
(Partially pesudo-code)

Timestamp arr = <select arrival>;
Timestamp dep = <select departure>;

long diff = arr.getTime() - dep.getTime();
int hourDiff = (int)diff / 1000 / 60 / 60;
0
 
petmagdyCommented:
some thing like that:

public static float getTimeElapsedInHours(Date laterTime, Date earlierTime)
{
      long l1 = laterTime.getTime();
      long l2 = earlierTime.getTime();
      long difference = l1 - l2;

  return ( ( (float) difference ) / (1000.0f * 60.0f * 60.0f)  );
}
0
 
rcmbAuthor Commented:
Works great.

Thanks again,
Curtis
0
 
CEHJCommented:
8-)

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.