Convert date and time to string format
Note
While datestr
returns text representing dates and times, it is
recommended that you use datetime
values to represent points in time,
and then convert them to text using the char
, cellstr
, or string
functions.
converts the DateString
= datestr(t
)datetime
values in the input array t
to text
representing dates and times.
The datestr
function returns a character array with m
rows, where m
is the total number of datetime
values in
t
. By default, datestr
returns text in the format,
day-month-year hour:minute:second. If hour:minute:second is 00:00:00
, then
the text returned has the format, day-month-year.
converts date vectors to text representing dates and times. The DateString
= datestr(DateVector
)datestr
function returns a character array with m
rows, where m
is the total number of date vectors in DateVector
.
converts serial date numbers to text representing dates and times. The
DateString
= datestr(DateNumber
)datestr
function returns a character array with m
rows, where m
is the total number of date numbers in
DateNumber
.
specifies the format of the output text using DateString
= datestr(___,formatOut
)formatOut
. You can use
formatOut
with any of the input arguments in the previous
syntaxes.
converts DateString
= datestr(DateStringIn
)DateStringIn
to
text in the format, day-month-year hour:minute:second. All dates and
times represented in DateStringIn
must have the
same format.
converts DateString
= datestr(DateStringIn
,formatOut
,PivotYear
)DateStringIn
to DateString
,
in the format specified by formatOut
, and using
optional PivotYear
to interpret dates that specify
the year as two characters.
returns the date in the language of the current locale. This language is the language you
select by means of your computer's operating system. If you leave DateString
= datestr(___,'local'
)'local'
out of the argument list, datestr
returns text in the default language,
which is US English. Use 'local'
with any of the previous syntaxes. The
'local'
argument must be last in the argument sequence.
To convert text not in a predefined MATLAB® date format, first convert the text to a date number, using either the
datenum
or datevec
functions.