now

Current date and time as a serial date number.

Category: Language Fundamentals > Data Types

Syntax

t = now

Returns the current local date and time as days since year 0.

Description

now returns a datenum, the same kind of value datenum produces. Because each call reads the clock, the result differs every time, so it is not suited for code that must give reproducible results. For new code datetime('now') is usually preferred, since it works with the modern date and time functions.

Convert the number to text with datestr(now).

Output arguments

t
Double scalar: the integer part is the day, the fractional part the time of day.

Example

t = now;
class(t)
t > datenum(2020, 1, 1)
Output
ans = 'double'
ans = logical
   1

The value of now changes at every run, so the example tests it instead of printing it.

See also

datetime datenum datestr clock tic