datestr
(Not recommended; use string
or char
) Convert
date and time to string format
datestr
is not recommended. To convert datetime
values to text, use the string
or char
function instead. For more information on updating your code, see Version History or Replace Discouraged Instances of Serial Date Numbers and Date Strings.
Syntax
Description
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
.
Note: In some circumstances, datestr
interprets a date vector as though it were a vector of six date numbers. For more information,
see Converting Date Vector Returns Unexpected Output.
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.
Examples
Input Arguments
Output Arguments
Tips
To convert text not in a predefined MATLAB® date format, first convert the text to a date number, using either the
datenum
ordatevec
functions.