Dim startTime As Date
Dim endTime As Date
Dim diff As Date
Dim minutes As Long
' 開始時刻と終了時刻を設定
startTime = #6:00:00 PM# ' 18:00:00
endTime = #4:00:00 PM# ' 16:00:00
' 日をまたいでいるかどうかをチェック
If endTime < startTime Then
' 翌日の時間として計算
diff = DateAdd("d", 1, endTime) - startTime
Else
' 同一日内の計算
diff = endTime - startTime
End If
' 差分を分に変換
minutes = DateDiff("n", startTime, DateAdd("d", IIf(endTime < startTime, 1, 0), endTime))
' 結果を表示
Debug.Print "差分は " & minutes & " 分です。"
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme