MATLAB Function Reference    
datestr

Date string format

Syntax

Description

The datestr function converts serial date numbers (defined by datenum) and date vectors (defined by datevec) into date strings.

str = datestr(DT,dateform) converts a single date vector, or each element of an array of serial date numbers to a date string. Date strings with two-character years, e.g., 12-june-12, are assumed to lie within the 100-year period centered about the current year.

str = datestr(DT,dateform,P) uses the specified pivot year as the starting year of the 100-year range in which a two-character year resides. The default pivot year is the current year minus 50 years.

The optional argument dateform specifies the date format of the result. dateform can be either a number or a string:

dateform
(number)

dateform (string)
Example
0
'dd-mmm-yyyy HH:MM:SS'
01-Mar-2000 15:45:17
1
'dd-mmm-yyyy'
01-Mar-2000
2
'mm/dd/yy'
03/01/00
3
'mmm'
Mar
4
'm'
M
5
'mm'
03
6
'mm/dd'
03/01
7
'dd'
01
8
'ddd'
Wed
9
'd'
W
10
'yyyy'
2000
11
'yy'
00
12
'mmmyy'
Mar00
13
'HH:MM:SS'
15:45:17
14
'HH:MM:SS PM'
3:45:17 PM
15
'HH:MM'
15:45
16
'HH:MM PM'
3:45 PM
17
'QQ-YY'
Q1-01
18
'QQ'
Q1
19
'dd/mm'
01/03
20
'dd/mm/yy'
01/03/00
21
'mmm.dd.yyyy HH:MM:SS'
Mar.01,2000 15:45:17
22
'mmm.dd.yyyy'
Mar.01.2000
23
'mm/dd/yyyy'
03/01/2000
24
'dd/mm/yyyy'
01/03/2000
25
'yy/mm/dd'
00/03/01
26
'yyyy/mm/dd'
2000/03/01
27
'QQ-YYYY'
Q1-2001
28
'mmmyyyy'
Mar2000
29 (ISO 8601)
'yyyy-mm-dd'
2000-03-01
30 (ISO 8601)
'yyyymmddTHHMMSS'
20000301T154517
31
'yyyy-mm-dd HH:MM:SS'
2000-03-01 15:45:17

Time formats like 'h:m:s', 'h:m:s.s', 'h:m pm', ... can also be part of the input array DT. If you do not specify dateform, or if you specify dateform as -1, the date string format defaults to

1
if DT contains date information only, e.g., 01-Mar-1995
16
if DT contains time information only e.g., 03:45 PM
0
if DT is a date vector, or a string that contains both date and time information e.g., 01-Mar-1995 03:45

See Also

date, datetick, datenum, datevec


  datenum datetick