VBA Function: Second


The VBA Second function returns an integer corresponding to the seconds of the specified date or time.

Syntax Second


VBA Second Example

Using the Second function to get the appropriate time information:

Sub SecondExample1()
      myHour = #6:36:45PM#
      MsgBox Second(myHour) 'Returns: 45

End Sub

Or by date and time (for the same result):

Sub SecondExample2()
      myDate = #10/31/2020 6:36:45 PM#
      MsgBox Second(myDate) 'Returns: 45

End Sub

This function also accepts dates and times in text format:

Sub SecondExample3()
      myDate = "10/31/2020 18:36:45"
      MsgBox Second(myDate) 'Returns: 45

End Sub
Function that returns the time of the current time: HOUR
The function returns the minutes of the current time: MINUTE