MATLAB Function Reference    
datestr

Date string format

Syntax

Description

str = datestr(D,dateform) converts each element of the array of serial date numbers (D) to a 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(D,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

Time formats like 'h:m:s', 'h:m:s.s', 'h:m pm', ... may also be part of the input array D. If you do not specify dateform, the date string format defaults to

1
if D contains data information only (01-Mar-1995)
16
if D contains time information only (03:45 PM)
0
if D contains both date and time information (01-Mar-1995 03:45)

See Also

date, datenum, datevec


 datenum datetick