(Not recommended; use
datetime) Current date and time as serial
now is not recommended. To return the current date and time as a
datetime value, use
datetime instead. For more
information on updating your code, see Version History or Replace Discouraged Instances of Serial Date Numbers and Date Strings.
t = now returns the current date and time as a serial date number.
A serial date number represents the whole and fractional number of days starting from a
fixed, preset date (January 0,
Return and Convert Serial Date Numbers
Change the output display for numbers to long, fixed-decimal format. Then return the current date and time as a serial date number.
format longG t = now
t = 738948.258201272
The whole part of
t corresponds to the date, and the fractional part corresponds to the time of day. One way to show the date and time is to convert
t using the
d = datetime(t,'ConvertFrom','datenum')
d = datetime 03-Mar-2023 06:11:48
To represent the date alone, without the time of day, use the
floor function. Convert the result to a
datetime value for display.
t2 = floor(t)
t2 = 738948
d2 = datetime(t2,'ConvertFrom','datenum')
d2 = datetime 03-Mar-2023
MATLAB® Online™ returns the current date and time in Coordinated Universal Time (UTC) rather than local time.
To represent the current date and time as a serial date number, as text, or as a
datetimevalue, use the function calls shown in the table.
Current date as a serial date number
Current time as a serial date number
Current date and time as text
Current date and time as a
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.
Version HistoryIntroduced before R2006a
R2022b: Not recommended
There are no plans to remove
now. However, the
datetime function is recommended instead. The
type provides flexible date and time formats, storage out to nanosecond precision, and
properties to account for time zones and daylight saving time.
To return the current date and time as a
datetime value, call
datetime. You can call it without any input arguments, or with
"now" as the input argument.
d = datetime % or d = datetime("now")
d = datetime 15-Apr-2022 15:53:28