• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 489
  • Last Modified:

Time difference in seconds

Hello guys,

I am kind of a newbee...

Is there any way to know a time difference in seconds in standard ASP? The time difference will never be more than 100 seconds. I need to know that time difference between 2 times, but the problem I have is when the process runs, for example, from 11:59:25 PM to 00:00:34 AM (for the day change).

Thanks!
0
pvg1975
Asked:
pvg1975
  • 2
  • 2
1 Solution
 
Ryan ChongCommented:
try:
<%
	
	function getTimeDiff(t1, t2)
		if isDate(t1) = false or isDate(t2) = false then
			getTimeDiff = "-"
		else
			dummyToday = DateSerial(2000,1,1)
			dummyToday2 = DateSerial(2000,1,2)
			
			d1 = CDate(t1)
			d2 = CDate(t2)
			
			if d1 > d2 then
				d1 = dummyToday + d1
				d2 = dummyToday2 + d2
				total = DateDiff("s", d1, dummyToday2) + DateDiff("s", dummyToday2, d2)
			else
				total = DateDiff("s", d1, d2)
			end if
			getTimeDiff = total
		end if
	end function
	
	response.write getTimeDiff("11:59:25 PM", "00:00:34 AM")
	
%>

Open in new window

0
 
DimitrisSenior Solution ArchitectCommented:
here you are, you will use datediff

datediff("s","1/1/2009 11:59:25 PM","1/2/2009 00:00:34 AM")

Please keep in mind that my date format is MM/DD/YYYY
0
 
pvg1975Author Commented:
Thanks for the solution!
0
 
Ryan ChongCommented:
huh.. hmmm
0
 
DimitrisSenior Solution ArchitectCommented:
sorry ryancys,
I haven't seen your post because i had the question open
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now