0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

時間の差分を分単位で求める方法

Posted at
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 & " 分です。"
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?