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
Columns 1 through 2

   31-Aug-2022 03:40:06.654   31-Aug-2022 03:40:21.654

Column 3

   31-Aug-2022 03:40:36.654

s = second(t)
s = 1×3

    6.6547   21.6547   36.6547

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