converting date and time string to datetime object

I am trying to read several text files each has 4 variables, the first coumn has the date and time values otgether in the following format
''2022-02-16T15:50:00.000Z'', and I would like to convert them in the following format "20220216155000".
I would like to convert theis into a datetmir object so i can use these vaues to compare to other dates and times from a different tables.
I am using the following lines for converion
for x = 1:length(Ionotable.x_Time) %x_Time is the column where the date and tie values are stored
Ionotable(x,1) = datetime(string(x),'InputFormat','yyMMddHHmmss');
end
but I am getting the follwoing error
Error using datetime (line 651)
Unable to convert '1' to datetime using the format 'yyMMddHHmmss'.
Error in Ionosonde_Data (line 23)
Ionotable(x,1) = datetime(string(x),'InputFormat','yyMMddHHmmss');

 採用された回答

VBBV
VBBV 2022 年 3 月 30 日
編集済み: VBBV 2022 年 3 月 30 日

0 投票

k = 1;
while k<=length(Ionotable.x_Time)
x = (Ionotable.x_Time(k)) %x_Time is the column where the date and tie values are stored
Ionotable(k,1) = datetime(string(x),'InputFormat','yyMMddHHmmss');
k = k+1;
end

5 件のコメント

Salma fathi
Salma fathi 2022 年 3 月 30 日
編集済み: Salma fathi 2022 年 3 月 30 日
Thank you for replying to my question,
I am getting the follwoing error now,
Error using datetime (line 651)
Unable to convert '2022-01-01T00:00:00.000Z' to datetime using the format 'yyyyMMddHHmmss'.
Error in Ionosonde_Data (line 24)
Ionotable(ii,1) = datetime(string(x),'InputFormat','yyyyMMddHHmmss');
>>
VBBV
VBBV 2022 年 3 月 30 日
Ionotable(k,1) = datetime(string(x),'InputFormat','uuuu-MM-dd''T''HH:mmXXX','TimeZone','UTC');
use a different input format
VBBV
VBBV 2022 年 3 月 30 日
Ionotable(k,1) = datetime(string(x),'InputFormat','uuuu-MM-dd''T''HH:mmXXX','TimeZone','UTC');
Itable(k,1) = datetime(string(Ionotable(k,1)),'InputFormat','yyMMddHHmmss') %
2 step conversion may be needed
Salma fathi
Salma fathi 2022 年 3 月 30 日
thank you problem solved.
VBBV
VBBV 2022 年 3 月 30 日
Please accept the answer if it solved. :) thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDates and Time についてさらに検索

製品

リリース

R2021b

質問済み:

2022 年 3 月 30 日

コメント済み:

2022 年 3 月 30 日

Community Treasure Hunt

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

Start Hunting!

Translated by