Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calculate date difference

Posted on 2004-10-25
5
Medium Priority
?
2,529 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:rcmb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 2000 total points
ID: 12402124
(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
 
LVL 13

Expert Comment

by:petmagdy
ID: 12402165
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
 
LVL 12

Author Comment

by:rcmb
ID: 12402744
Works great.

Thanks again,
Curtis
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12402780
8-)

0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Suggested Courses

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question