Main Content

second

Seconds component of input date and time

Description

example

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

Examples

collapse all

t1 = datetime('now','Format','dd-MMM-yyyy HH:mm:ss.SSS');
t = t1 + seconds(30:15:60)
t = 1x3 datetime
   19-Aug-2023 14:49:06.815   19-Aug-2023 14:49:21.815   19-Aug-2023 14:49:36.815

s = second(t)
s = 1×3

    6.8159   21.8159   36.8159

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