Filter löschen
Filter löschen

How do I convert a string to a date?

2 Ansichten (letzte 30 Tage)
ARGY B
ARGY B am 14 Aug. 2019
Kommentiert: Star Strider am 15 Aug. 2019
I have a txt file with dates in the following form:
200309302300
200309302310
200309302320
......etc
How can I convert these strings into date form?
something like : 2003-Sep-30 23:00 or 2003-09-30 23:00

Akzeptierte Antwort

Star Strider
Star Strider am 14 Aug. 2019
I am not certain if the numbers are themselves strings, or numbers.
If they are numbers, this works:
numdate = [200309302300
200309302310
200309302320];
dn = datenum(num2str(numdate), 'yyyymmddHHMM') % Date Numbers
dv = datevec(dn)
dt = datetime(num2str(numdate), 'InputFormat','yyyyMMddHHmm') % ‘datetime’ Array
If they are strings, omit the str2num calls and just insert them directly.
  2 Kommentare
ARGY B
ARGY B am 15 Aug. 2019
Thank you :)
Star Strider
Star Strider am 15 Aug. 2019
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by