Comparing Times

1. Senior Member
Join Date
Dec 1969
Posts
701

## Comparing Times

Is there a function that compares two times, like the dateDiff() function, but can return hours and/or minutes.

2. Senior Member
Join Date
Dec 1969
Posts
19,082

## RE: Comparing Times

no, but it&#039;s a relatively trivial task to write one of your own.

3. Senior Member
Join Date
Dec 1969
Posts
623

## something like this

http://www.aspmessageboard.com/forum/asp.asp?M=445255&F=20&P=1

4. Senior Member
Join Date
Dec 1969
Posts
155

## RE: Comparing Times

&#039;compare minutes because you can easyly transform to hours+minutes<BR> <BR>MyHoursAndMinutes = datediff("n",mydate1, mydate2)/60<BR><BR>&#039;**substract the integer part to get the decimal part<BR>myMinutes = MyHoursAndMinutes - CInt(MyHoursAndMinutes)<BR><BR>&#039;get the hours<BR>MyHours = CInt(MyHoursAndMinutes)<BR><BR>&#039;get the minutes<BR>myMinutes = myMinutes*60<BR><BR>&#039;display the result, you should put it in a function<BR>response.write "hours=" & myHours & " ; Minutes=" & minutes<BR><BR>&#039;I didnt try it , but it is an idea. For more details replay.<BR><BR>pp:<BR><BR>and for the other guy, why he bothers to write something if he is not helping? "No question is stupid or advanced blah blah blha" is not something written in the header of this messageboard?

5. Senior Member
Join Date
Dec 1969
Posts
701

## I wrote my own function

I wrote my own timeDiff function instead, so I can return how many hours or minutes between the two times, if you&#039;re intrested in a function like this feel free to take mine:<BR><BR>FUNCTION timeDiff(what,date1,date2)<BR>IF what="h" THEN<BR><BR>h = Split(date1,":")<BR>date1=cInt(h(0))<BR><BR>h= Split(date2, ":")<BR>date2=cInt(h(0))<BR><BR>IF date1 &#062; date2 THEN<BR>remainingHours=date1-date2<BR>ELSEIF date1 &#060; date2 THEN<BR>remainingHours=date2-date1<BR>ELSE<BR>remainingHours=0<BR>END IF<BR>timeDiff=remainingHours<BR><BR>ELSEIF what="m" THEN<BR><BR>h = Split(date1,":")<BR>hour1=cInt(h(0))<BR>date1=cInt (h(1))<BR><BR>h= Split(date2, ":")<BR>hour2=cInt(h(0))<BR>date2=cInt(h(1))<BR><B R>IF hour1 &#062; hour2 THEN<BR>theHour=(hour1-hour2)*60<BR>ELSEIF hour1 &#060; hour2 THEN<BR>theHour=(hour2-hour1)*60<BR>ELSE<BR>theHour=0<BR>END IF<BR><BR>IF date1 &#062; date2 THEN<BR>remainingMins=(date1-date2)+theHour<BR>ELSEIF date1 &#060; date2 THEN<BR>remainingMins=(date2-date1)+theHour<BR>ELSE<BR>remainingMins=0<BR>END IF<BR>timeDiff=remainingMins<BR><BR>ELSE<BR>timeDi ff="Invalid Character, use ""m"" or ""h"""<BR><BR>END IF<BR><BR>END FUNCTION

6. Senior Member
Join Date
Dec 1969
Posts
623

## RE: I wrote my own function

Naa, you do not consider the date here, only the hour/minutes. Would you buy that?<BR><BR>so timeDiff ( &#039;h&#039; &#039;08/31/02 12:00&#039;, &#039;07/31/02 01:00&#039; ) would be 1 ???<BR><BR>use the dateDiff function and compute whatever you want from there

7. Senior Member
Join Date
Dec 1969
Posts
701

## RE: I wrote my own function

I know that&#039;s what I want to do, I&#039;m only dealing with the time in 00:00:00 format (time()) because I&#039;m tracking something from 24 hours ago that will only have a time attached to it, I suppose I didn&#039;t state how specific I wanted it to be, thanks for your help.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•