0

Day-Hour-Minutes 形式の VBScript を使用して、2 つの日付値の差を取得できますか?

4

1 に答える 1

8

これは HH::MM:SS の例です。これを DD::HH::MM に変更するのは簡単です

ASP FAQ - 日時ルーチンの操作

<% 
    Function TimeSpan(dt1, dt2) 
        If (isDate(dt1) And IsDate(dt2)) = false Then 
            TimeSpan = "00:00:00" 
            Exit Function 
        End If 

        seconds = Abs(DateDiff("S", dt1, dt2)) 
        minutes = seconds \ 60 
        hours = minutes \ 60 
        minutes = minutes mod 60 
        seconds = seconds mod 60 

        if len(hours) = 1 then hours = "0" & hours 

        TimeSpan = hours & ":" & _ 
            RIGHT("00" & minutes, 2) & ":" & _ 
            RIGHT("00" & seconds, 2) 
    End Function 

    d1 = "2002-03-27 9:20:25 AM" 
    d2 = "2002-03-27 9:20:45 AM" 

    Response.Write TimeSpan(d1, d2) 
%>

次のようなもの:(わからない、vbscriptがわからない)

<% 
    Function TimeSpan(dt1, dt2) 
        If (isDate(dt1) And IsDate(dt2)) = false Then 
            TimeSpan = "00:00:00" 
            Exit Function 
        End If 

        seconds = Abs(DateDiff("S", dt1, dt2)) 
        minutes = seconds \ 60 
        hours = minutes \ 60 
        days  = hours \ 24
        minutes = minutes mod 60 
        seconds = seconds mod 60 
        hours   = hours   mod 24 

        if len(hours) = 1 then hours = "0" & hours 

        TimeSpan = days& ":" & _ 
            RIGHT("00" & hours , 2) & ":" & _ 
            RIGHT("00" & minutes, 2) 
    End Function 

    d1 = "2002-03-27 9:20:25 AM" 
    d2 = "2002-03-27 9:20:45 AM" 

    Response.Write TimeSpan(d1, d2) 
%>
于 2012-12-11T13:35:14.083 に答える