time differences... How to get the diff between 2

Results 1 to 6 of 6

Thread: time differences... How to get the diff between 2

  1. #1
    Join Date
    Dec 1969

    Default time differences... How to get the diff between 2

    Hey guys I have somewhat of a problem. This is what I need to be able to do. A user will enter the time the sun will come up and the time it will go down. How do I get the difference between these two. The obvious answer, subtract them, doesn&#039;t work. I need to find out the total number of hours the sun will be up. It seems simple but Ihave tried a bunch of things I need it to display like this eg 8:22. I have tried using modulus but I can&#039;t get the proper variable type to work eg Cint or CDbl etc.<BR><BR>Please help<BR>Mike M

  2. #2
    Heaven's Martini Guest

    Default over complication is the thief of time

    look in the vbs reference for<BR><BR>DateDiff<BR><BR>it works wonders.<BR>

  3. #3
    Reggie Guest

    Default You'd be surprised...

    how much support vbscript has from dates/times. Use datediff()<BR>http://msdn.microsoft.com/scripting/vbscript/doc/vsfctDateDiff.htm<BR><BR>The easiest way would probably be to get the time in minutes, then divide that by 60 to get the hours, then use the leftover minutes.

  4. #4
    Join Date
    Dec 1969

    Default RE: time differences... How to get the diff betwee

    use the function datediff -- see: http://www.devguru.com/Technologies/vbscript/quickref/datediff.html<BR><BR>URL might wrap!<BR><BR>buzz

  5. #5
    Join Date
    Dec 1969

    Default HERE'S YOUR CODE!

    DateDiff("n", time_start, time_end)<BR><BR><BR>timestart and timeend are minutes

  6. #6
    Mike M. Guest


    used some of your comments to write this but I finally got it working here is the code if NE one is interested:<BR><BR>&#060;%<BR>time1= #8:41# &#039;example times<BR>time2 = #9:43#<BR>time2n = time2 + #12:00#<BR><BR>nummindiff= Cint(DateDiff("n", time1, time2n))<BR>numhrsdiff_mod= nummindiff MOD 60<BR>numhrsdiff = DateDiff("h", time1, time2n)<BR><BR>if numhrsdiff &#060;&#062; Cint(nummindiff/60) Then<BR> nummindiff = 60 - nummindiff<BR>End if<BR><BR><BR>if numhrsdiff_mod &#060; 10 Then<BR> numhrsdiff_mod = 0 & numhrsdiff_mod <BR>End if<BR><BR><BR>if DatePart("n", time1) &#060;= DatePart("n", time2n) Then<BR> Response.write "difference is " & numhrsdiff & ":" & numhrsdiff_mod <BR>Else<BR> Response.write "difference is " & numhrsdiff -1 & ":" & numhrsdiff_mod <BR>End if<BR><BR>%&#062;

Posting Permissions

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