This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

now

Current date and time as serial date number

Syntax

t = now

Description

example

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, 0000).

Examples

collapse all

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 = 
            737528.0085395

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 datetime function.

d = datetime(t,'ConvertFrom','datenum')
d = datetime
   13-Apr-2019 00:12:17

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 = 
      737528

d2 = datetime(t2,'ConvertFrom','datenum')
d2 = datetime
   13-Apr-2019 00:00:00

Limitations

  • MATLAB Online returns the current date and time in Coordinated Universal Time (UTC) rather than local time.

More About

collapse all

January 0, 0000

Date specified to include a year 0 in the proleptic Gregorian calendar. For more information, see January 0 and Year zero.

Tips

  • To represent the current date and time as a serial date number, as text, or as a datetime value, use the function calls shown in the table.

    Function Call

    Output

    floor(now)

    Current date as a serial date number

    rem(now,1)

    Current time as a serial date number

    datestr(now)

    Current date and time as text

    char(datetime('now'))

    string(datetime('now'))

    datetime('now')

    Current date and time as a datetime value

    datetime(now,'ConvertFrom','datenum')

Introduced before R2006a