ziaguintu6
asked on
how can i get the result of two time.
how can i get the result of two time.
sample
7:05 AM - 8:30 AM
or
5:48 PM - 7:30 PM
thanks
sample
7:05 AM - 8:30 AM
or
5:48 PM - 7:30 PM
thanks
what language
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:3 0, 7:05)
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"
diffInSec=DateDiff("n",8:3
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).
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).
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;
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;
ASKER
i am using asp and i can't understand your answer. i assigned the two dates from two variables
thanks
thanks
LOL: About the only thing no one covered ;-)
I can't help with that :-(
I can't help with that :-(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The diffInMinutes=DateDiff("n" ,8:30, 7:05)
will return the difference in minutes and diffInSec=DateDiff("n",8:3 0, 7:05)
will return the difference in seconds
will return the difference in minutes and diffInSec=DateDiff("n",8:3
will return the difference in seconds
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. ;^)
I usually do all my ASP stuff in JScript (or occasionally ActivePython) and only use VBScript when someone holds a gun to my head. ;^)