datetime

Methods

Method Reference: datetime.datestr

datetime: S = datestr (T)
datetime: S = datestr (T, f)
datetime: S = datestr (…, opt)

Convert datetime array to a character array of date strings.

S = datestr (T) converts the datetime array T to a character array S with one date string per row, using the default format of the core datestr function.

S = datestr (T, f) uses the format specified by f, a format number or a format string that follows the legacy datestr field codes, in which 'mm' denotes months and 'MM' denotes minutes. Any further arguments opt are passed on to the core datestr function.

datestr is provided for compatibility with legacy code. It renders the wall-clock components of T and, for a zoned array, does not include the time zone. For time-zone-aware formatting with the modern Unicode (LDML) field codes, use char, cellstr, or set the Format property of T instead.

The legacy field codes have no way to write a 60th second, so for a 'UTCLeapSeconds' array an inserted second folds backward onto the 59th, as it does in datenum.

Source Code: datetime

datestr produces text using the legacy datestr format codes. Note that here mm means months and MM means minutes — the reverse of the modern Unicode (LDML) codes used by char and the 'Format' property, which are the preferred way to format a datetime.

 t = datetime (2024, 3, 9, 6, 0, 0)
t =
  datetime

   09-Mar-2024 06:00:00
 datestr (t)
ans = 09-Mar-2024 06:00:00
 datestr (t, 'yyyy-mm-dd HH:MM:SS')
ans = 2024-03-09 06:00:00