Main Content

second

Seconds component of input date and time

Description

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.

example

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
   20-Jul-2024 15:22:20.890   20-Jul-2024 15:22:35.890   20-Jul-2024 15:22:50.890

s = second(t)
s = 1×3

   20.8901   35.8901   50.8901

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