datestr
Convert date and time to string format.
Syntax
dateAsString = datestr(dateVector)
dateAsString = datestr(dateNumber)
dateAsString = datestr(..., formatOut)
dateAsString = datestr(dateAsStringIn)
dateAsString = datestr(dateAsStringIn, formatOut, pivotYear)
dateAsString = datestr(..., 'local')
Input argument
dateVector - Date vectors or matrix.
dateNumber - Serial date numbers: An array of positive double-precision floating-point numbers.
formatOut - character vector, string scalar or integer value (-1 default): Output format for representing dates and times
dateAsStringIn - character vector, cell array or string array: text denoting dates and times to convert.
pivotYear - integer value: present minus 50 years (default).
'local' - returns the date in the language of the current locale.
Output argument
dateAsString - character vector or two-dimensional character array: text denoting dates and time.
Description
dateAsString = datestr(dateVector) converts date vectors into text that represents the corresponding dates and times. It returns a character array with m rows, where m is the number of date vectors in dateVector.
dateAsString = datestr(dateNumber) converts serial date numbers into text representing dates and times. The output is a character array with m rows, where m is the number of date numbers in dateNumber.
dateAsString = datestr(..., formatOut) allows you to specify the format of the output text using formatOut. You can apply this option with any of the previous input types.
dateAsString = datestr(dateAsStringIn) converts the input string dateAsStringIn into a text format of day-month-year hour:minute:second. All dates in dateAsStringIn must follow the same format.
dateAsString = datestr(dateAsStringIn, formatOut, pivotYear) converts dateAsStringIn into the format specified by formatOut, while using an optional pivotYear to interpret two-digit years.
dateAsString = datestr(..., 'local') returns the date in the language of the system's current locale. If 'local' is omitted, the default language is US English. The 'local' option can be used with any of the previous syntaxes, and must be the last argument in the sequence.
Supported format conversion:
dd-mmm-yyyy HH:MM:SS 10-Mar-2010 16:48:17
dd-mmm-yyyy 10-Mar-2010
mm/dd/yyyy 03/10/2010
mm/dd/yy 03/10/00
mm/dd 03/10
mmm.dd,yyyy HH:MM:SS Mar.10,2010 16:48:17
mmm.dd,yyyy Mar.10,2010
yyyy-mm-dd HH:MM:SS 2010-03-10 16:48:17
yyyy-mm-dd 2010-03-10
yyyy/mm/dd 2000/03/10
HH:MM:SS 16:48:17
HH:MM:SS PM 3:48:17 PM
HH:MM 16:48
HH:MM PM 3:35 PM
If format is not specified, the default format is dd-mmm-yyyy.
If format is specified and not using predefined format, the format must be specified as a character vector or string scalar composed of symbolic identifiers.
The format of the input text for representing dates and times, expressed as a character vector or string scalar composed of symbolic identifiers.
yyyy
Year in full
1995, 2012
yy
Year in two digits
89, 01
Quarter year using letter Q and one digit
Q1
mmmm
Month using full name
March, December
mmm
Month using first three letters
Mar, Dec
mm
Month in two digits
04, 12
m
Month using capitalized first letter
M, D
dddd
Day using full name
Monday, Tuesday
ddd
Day using first three letters
Mon, Tue
dd
Day in two digits
06, 21
d
Day using capitalized first letter
M, T
HH
Hour in two digits (no leading zeros when symbolic identifier AM or PM is used)
06, 6 AM
MM
Minute in two digits
11, 01
SS
Second in two digits
06, 59
FFF
Millisecond in three digits
056
AM or PM
AM or PM inserted in text representing time
5:46:02 PM
Examples
See also
History
1.8.0
initial version
Author
Allan CORNET
Last updated