Solved

how can i get the result of two time.

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

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

thanks
0
Comment
Question by:ziaguintu6
  • 3
  • 3
  • 2
  • +2
12 Comments
 
LVL 12

Expert Comment

by:Dean OBrien
Comment Utility
what language
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
VBScript example:

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

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

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




0
 
LVL 15

Expert Comment

by:jimmack
Comment Utility
Do you mean you want the difference between the two times?

In Java:

        Calendar startTime = Calendar.getInstance();
        startTime.clear();
        startTime.set(2003, 10, 11, 7, 5);
        Calendar endTime = Calendar.getInstance();
        endTime.clear();
        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).

0
 
LVL 11

Expert Comment

by:Zontar
Comment Utility
JavaScript:

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));

PHP:

$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;
0
 

Author Comment

by:ziaguintu6
Comment Utility
i am using asp and i can't understand your answer. i assigned the two dates from two variables

thanks
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 15

Expert Comment

by:jimmack
Comment Utility
LOL: About the only thing no one covered ;-)

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

Accepted Solution

by:
Zontar earned 25 total points
Comment Utility
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
%>
0
 
LVL 35

Assisted Solution

by:YZlat
YZlat earned 25 total points
Comment Utility
<%
Dim diffInMinutes, diffInSec
diffInMinutes=DateDiff("n",8:30, 7:05)
diffInSec=DateDiff("n",8:30, 7:05)

%>
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
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
0
 
LVL 11

Expert Comment

by:Zontar
Comment Utility
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. ;^)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
iOS retina Display, HTML Email Signature 5 475
Share post from Facebook Tab Application 6 24
Owl Carousel 6 141
WCAG audit tools 1 51
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now