Axel.Schweiß
Axel.Schweiß

Reputation: 67

Import datetime from txt

I am trying to read a table with timeseries data.

The first column defines the date/time in the format 01.01.1998 00:00.

I read the table by:

T = readtable('Abflussdaten.txt','DatetimeType','text');

Then I tried to convert the first column to datetime:

D = T.Datum;
date = datetime(D,'InputFormat','yyyy-MM-dd HH:mm')

This gives me: Error using datetime (line 616) Unable to parse date/time text using the format 'yyyy-MM-dd HH:mm'.

This is how the table looks like:

Datum;Q_Kempten;Q_Sonthofen
01.01.1998 00:00;27.010;9.6700
01.01.1998 01:00;26.810;9.6600
01.01.1998 02:00;26.610;9.6500

What am I doing wrong? I think it is related to the date format, but it seems to be correct.

Thanks for any help

Upvotes: 1

Views: 186

Answers (2)

Paolo
Paolo

Reputation: 26074

Two issues:

  • Your date is in the wrong order (yyyy MM dd instead of dd MM yyyy).
  • You are using the wrong separator (- instead of .).

Use:

date = datetime(D,'InputFormat','dd.MM.yyyy HH:mm')

Upvotes: 1

VeryNice
VeryNice

Reputation: 81

Your date format seems wrong. Try changing your date format from yyyy-MM-dd HH:mm to dd-MM-YYYY HH:mm.

Upvotes: 0

Related Questions