Filter löschen
Filter löschen

Problems using "datetime" cont.

1 Ansicht (letzte 30 Tage)
Andy Wileman
Andy Wileman am 17 Mär. 2021
Kommentiert: Andy Wileman am 17 Mär. 2021
Hi,
Having solved problems with getting the current date from a structure into a table (thank you Adam). Using "datetime" still does not seem to be carrying out the conversion. Any thoughts?
Kind regards,
Andy
table
Dates
_________________________________
"12/24/2008 9:59:47 AM.786743640"
%Current file format{'12/24/2008 9:59:47 AM.786743640'}
%Fileformat to convert to = data-20130325T004512Z.mat
date=cell2mat(dateName);
data=cell2mat(timeDom);
N = date
T = table(string(N), 'VariableNames', {'Dates'})
dt = datetime('T.Dates','Format','yyyyMMdd''T''HHmmss''Z')
% TODO: Save files
save(data, '-append', '-struct', 'dt');
Error using datetime (line 640)
Unable to convert 'T.Dates' to datetime using the format 'yyyyMMdd'T'HHmmss'Z'.
Error in extractor (line 20)
dt = datetime('T.Dates','Format','yyyyMMdd''T''HHmmss''Z')

Akzeptierte Antwort

Stephen23
Stephen23 am 17 Mär. 2021
Bearbeitet: Stephen23 am 17 Mär. 2021
You should probably specify the input format to match the provided string:
S = "12/24/2008 9:59:47 AM.786743640";
D = datetime(S, 'InputFormat','MM/dd/yyyy h:m:s a.SSSSSSSSS')
D = datetime
24-Dec-2008 09:59:47
D.Format = 'yyyyMMdd''T''HHmmss''Z'''
D = datetime
20081224T095947Z
You also need to refer to the table, not define a literal character vector:
datetime( T.Dates ,...) % correct way to refert to table T.
datetime('T.Dates',...) % defines a character vector, does not help you.
  3 Kommentare
Stephen23
Stephen23 am 17 Mär. 2021
@Andy Wileman: note that I assumed that the trailing decimal fraction are fractional seconds. If they represent some other data, then you will need to make the required changes.
Andy Wileman
Andy Wileman am 17 Mär. 2021
I think they are trailing seconds, as the data is from data aquisition. Once again, thanks.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

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

Tags

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by