Convert char to date

11 次查看(过去 30 天)
BA 2022-7-17
评论: BA ,2022-7-17
Basically, I have a table with dates that are currently char's and I want to convert them into datetime format. This is how the dates are now:
The problem is that these dates conflict with another dataset where the dates are like this:
I'm trying to make the dates appear the same for both tables and this was the command I ran:
Data.StudyDate_converted = cellfun(@(x) datetime(x), Data.StudyDate, 'UniformOutput', false);
This isn't doing the trick. The new column that the table creates in the table shows a 1x1 date time in each cell and when you click on it, the date reads as 04-Feb-0022
If someone knows a fix, please let me know. I attached the dataset that I want to convert from a char to datetime to this post in case its needed. The specific variable I want to convert from char to datetime is "StudyDate".
Thanks in advance


Walter Roberson
Walter Roberson 2022-7-17
filename = '';
Data = readtable(filename);
Data.StudyDate_converted = datetime(Data.StudyDate, 'Format', 'M/d/yy');
ans = 3×9 table
StartDate EndDate SubID Group StudyDay MetricWireID Protocol StudyDate StudyDate_converted ___________ ___________ _________ _______ ________ _____________________________ ________ ____________ ___________________ 09-Mar-2022 06-Apr-2022 2.176e+07 {'OUD'} 1 {'7sadd0a7sd9a8sd9a8d0as8da'} 41 {'03/09/22'} 3/9/22 09-Mar-2022 06-Apr-2022 2.176e+07 {'OUD'} 2 {'7sadd0a7sd9a8sd9a8d0as8da'} 41 {'03/10/22'} 3/10/22 09-Mar-2022 06-Apr-2022 2.176e+07 {'OUD'} 3 {'7sadd0a7sd9a8sd9a8d0as8da'} 41 {'03/11/22'} 3/11/22

更多回答(0 个)





Community Treasure Hunt

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

Start Hunting!

Translated by