Adsense

2019年7月28日日曜日

【ACCESS/EXCEL/VBA】現在時刻ミリ秒まで取得を行う

VBAの[ NOW() ]や[ DATE() ]関数ではミリ秒の取得が行えない。
ミリ秒まで取得を行いたい場合は[ Win32API ]を使用して別途自作する必要がある。

■以下取得関数サンプル
Option Compare Database
Option Explicit

Private Type systemTime
    Year As Integer
    Month As Integer
    DayOfeek  As Integer
    Day  As Integer
    Hour As Integer
    Minute As Integer
    Second As Integer
    Milliseconds As Integer
End Type

Private Declare Sub GetSystemTime Lib "kernel32" (systemTime As systemTime)

' 現在日時をミリ秒まで取得する関数
Public Function GetDetailSysTime() As String
    Dim sysTime As systemTime
    GetSystemTime sysTime
    
    GetDetailSysTime = CStr(sysTime.Year) & "/" & _
                       Format(sysTime.Month, "00") & "/" & _
                       Format(sysTime.Day, "00") & " " & _
                       Format(sysTime.Hour, "00") & ":" & _
                       Format(sysTime.Minute, "00") & ":" & _
                       Format(sysTime.Second, "00") & "." & _
                       Format(sysTime.Milliseconds, "000")
End Function

0 件のコメント:

コメントを投稿