Seconds component of input date and time
s = second( 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.
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
and modify the
Find Second Number of Datetime Values
t1 = datetime('now','Format','dd-MMM-yyyy HH:mm:ss.SSS'); t = t1 + seconds(30:15:60)
t = 1x3 datetime Columns 1 through 2 26-Feb-2022 12:17:39.603 26-Feb-2022 12:17:54.603 Column 3 26-Feb-2022 12:18:09.603
s = second(t)
s = 1×3 39.6035 54.6035 9.6035
t — Input date and time
Input date and time, specified as a
If the time zone of
contain a value between 60 and 61 for any time that falls during a leap
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
secondType — Type of second values
'secondofminute' (default) |
Type of second values, specified as either
secondreturns the second of the minute.
secondreturns 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
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, see Tall Arrays.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version HistoryIntroduced in R2014b
R2022a: Serial date number and text inputs not recommended
Not recommended starting in R2022a
second supports serial date number and text inputs,
datetime values are recommended instead. The
datetime data type provides flexible date and time formats,
storage out to nanosecond precision, and properties to account for time zones and
daylight saving time.
To convert serial date numbers or text to
datetime values, use
datetime function. For
t = datetime(738427.656845093,"ConvertFrom","datenum"); s = second(t)
s = 51.4160
There are no plans to remove support for serial date number or text inputs.
second functions from Financial Toolbox and MATLAB combined
In previous releases, there were two
second functions: one in
MATLAB® that accepted
datetime values, and one in
Financial Toolbox that accepted serial date numbers or text values. As of R2022a, you
second without Financial Toolbox. When you call
second from MATLAB, it accepts all previous input types.
For example, you can make these calls with a serial date number and text from MATLAB:
s = second(738427.656845093)
s = 51.4160
s = second("2021/09/28 15:45:51.4160")
s = 51.4160
second accepts a second input for the date
format when the first input is not a
s = second(t,F)
In this syntax, specify
F using a valid date format as
documented for the
datestr function, though
'Q' format specifiers are not supported. For example:
s = second("2021/09/28 15:45:51.4160","yyyy/dd/mm hh:MM:ss.fff")
s = 51.4160