how can i get the result of two time.

Posted on 2003-11-11
Last Modified: 2010-04-06
how can i get the result of two time.

7:05 AM - 8:30 AM
5:48 PM - 7:30 PM

Question by:ziaguintu6
  • 3
  • 3
  • 2
  • +2
LVL 12

Expert Comment

by:Dean OBrien
ID: 9721202
what language
LVL 35

Expert Comment

ID: 9721922
VBScript example:

use DateDiff function.
DateDiff(interval, number, date)
Where interval could be one of those:

h      ---> Hour
n      ---> Minute
s      ---> Second

Dim diffInMinutes, diffInSec
diffInMinutes=DateDiff("n",8:30, 7:05)
diffInSec=DateDiff("n",8:30, 7:05)

LVL 15

Expert Comment

ID: 9721931
Do you mean you want the difference between the two times?

In Java:

        Calendar startTime = Calendar.getInstance();
        startTime.set(2003, 10, 11, 7, 5);
        Calendar endTime = Calendar.getInstance();
        endTime.set(2003, 10, 11, 8, 30);
        long diff = endTime.getTimeInMillis() - startTime.getTimeInMillis();
        System.out.println("diff = " + diff);

This give 5100000 (5100 seconds = 85 minutes = 1 hour 25 minutes).

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

LVL 11

Expert Comment

ID: 9726234

var today = new Date();
var year = today.getFullYear();
var month = today.getMonth();
var day = today.getDay();

var start = new Date(year, month, day, sHours, sMinutes, sSeconds).getTime();
var end = new Date(year, month, day, eHours, eMinutes, eSeconds).getTime();

//  you supply the hours, minutes, seconds for each

var diff = (end - start) * 1000; //  difference in seconds
var diffHours = Math.floor(diff / 3600);
var diffMinutes = Math.floor( (diff - (diffHours * 3600)) / 60 );
var diffSeconds = Math.floor(diff - (diffHours * 3600) - (diffMinutes * 60));


$start = mktime($s_hours, $s_minutes, $s_seconds);
$end = mktime($e_hours, $e_minutes, $e_seconds);

# you supply the hours. minutes, seconds for each

$diff = $end - $start;

$diff_formatted = date("G:i:s", $diff);

MySQL (pre-4.1.1):

SELECT DATE_SUB("2003-11-12 17:42:35", INTERVAL "12:30:20" HOUR_SECOND) AS difference;

(version 4.1.1 and higher)

SELECT SUBTIME("17:42:35", "12:30:20") AS difference;

Author Comment

ID: 9727236
i am using asp and i can't understand your answer. i assigned the two dates from two variables

LVL 15

Expert Comment

ID: 9727540
LOL: About the only thing no one covered ;-)

I can't help with that :-(
LVL 11

Accepted Solution

Zontar earned 25 total points
ID: 9727693
Well, you could just use JScript for your ASP (and the code I posted above). But since I enjoy suffering, here it is in ASP/VBScript ... ;^)

  Time1 = TimeValue("3:45:30AM")
  Time2 = TimeValue("5:25:40PM")

  H1 = Hour(Time1)
  M1 = Minute(Time1)
  S1 = Second(Time1)

  H2 = Hour(Time2)
  M2 = Minute(Time2)
  S2 = Second(Time2)

  Diff = TimeSerial(H2 - H1, M2 - M1, S2 - S1)

  HD = Hour(Diff)
  MD = Minute(Diff)
  SD = Second(Diff)

  Response.Write HD & ":" & MD & ":" & SD
  ' Displays: 13:40:10
LVL 35

Assisted Solution

YZlat earned 25 total points
ID: 9731060
Dim diffInMinutes, diffInSec
diffInMinutes=DateDiff("n",8:30, 7:05)
diffInSec=DateDiff("n",8:30, 7:05)

LVL 35

Expert Comment

ID: 9731065
The diffInMinutes=DateDiff("n",8:30, 7:05)
 will return the difference in minutes and diffInSec=DateDiff("n",8:30, 7:05)
will return the difference in seconds
LVL 11

Expert Comment

ID: 9732228
I didn't realise you could pass DateDiff a dummy argument like that, thanks for the tip.

I usually do all my ASP stuff in JScript (or occasionally ActivePython) and only use VBScript when someone holds a gun to my head. ;^)

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Menu Trouble 8 46
Auto Complete Using JQuery 5 89
css help 3 140
Web Application Architecture 6 78
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

820 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