Main Content


Seconds component of input date and time



s = second(t) returns the seconds component for each date and time specified in t. The seconds component of a date and time can include a fractional part.

The s output is a double array and contains values from 0 to less than 60. To assign values to the seconds components of values in t, use t.Second and modify the Second property.

s = second(t,secondType) returns the type of seconds of datetime array t, specified as either "secondofminute" or "secondofday".


collapse all

t1 = datetime('now','Format','dd-MMM-yyyy HH:mm:ss.SSS');
t = t1 + seconds(30:15:60)
t = 1x3 datetime
   13-Feb-2024 00:26:46.277   13-Feb-2024 00:27:01.277   13-Feb-2024 00:27:16.277

s = second(t)
s = 1×3

   46.2778    1.2778   16.2778

Input Arguments

collapse all

Input date and time, specified as a datetime array.

If the time zone of t is UTCLeapSeconds, then s can contain a value between 60 and 61 for any time that falls during a leap second occurrence.

To support existing code that previously required Financial Toolbox™, second also accepts serial date numbers and text as inputs, but they are not recommended. For more information, see Version History.

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).

This argument is valid only when t is a datetime array.

Extended Capabilities

Version History

Introduced in R2014b

expand all