Main Content




s = second(t) returns the second values, including a fractional part, for the datetime values in t. The s output is a double array the same size as t and contains values from 0 to less than 60.

For datetime values whose time zone is UTCLeapSeconds, the s output can contain a value between 60 and 61 for times that fall during a leap second occurrence.

s = second(t,secondType) returns the type of second number specified by secondType.

The second function returns the second numbers of datetime values. To assign second values to datetime array t, use t.Second and modify the Second property.


collapse all

t1 = datetime('now','Format','dd-MMM-yyyy HH:mm:ss.SSS');
t = t1 + seconds(30:15:60)
t = 1x3 datetime
Columns 1 through 2

   01-Sep-2021 10:38:39.935   01-Sep-2021 10:38:54.935

Column 3

   01-Sep-2021 10:39:09.935

s = second(t)
s = 1×3

   39.9356   54.9356    9.9356

Input Arguments

collapse all

Input date and time, specified as a datetime array.

Type of second values, specified as either 'secondofminute' or 'secondofday'.

  • If secondType is 'secondofminute', then second returns the second of the minute.

  • If secondType is 'secondofday', then second returns the second of the day, which (except for leap seconds) is in the range [0, 86400).

Extended Capabilities

Introduced in R2014b