datestr problem with minutes
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I'm encountering a problem with date conversion. I have a dataset column with dates in '1/5/2017 12:10:00AM' form and I want to convert it into '2017-05-01 00:10:00' format. I used the datestr function but the minutes are incorrect. All rows return with 00 minutes.
How can I fix this?
Thank you in advance, Vanessa
3 个评论
回答(2 个)
Walter Roberson
2017-6-29
t = datenum('1/5/2017 12:10:00AM' );
datestr(t, 'YYYY-mm-DD HH:MM:ss')
0 个评论
Andrei Bobrov
2017-6-29
编辑:Andrei Bobrov
2017-6-29
a = datetime('1/5/2017 12:10:00AM','I','dd/MM/yyyy hh:mm:ssa','F','yyyy-MM-dd HH:mm:ss')
4 个评论
Andrei Bobrov
2017-6-29
a = {'1/5/2017';
'1/5/2017 12:10:00AM';
'1/5/2017 12:15:00AM';
'1/5/2017 12:20:00AM';
'2/5/2017'};
t = ~cellfun(@isempty,regexp(a,'\d{4}$'));
a(t) = cellfun(@(x)[x,' 00:00:00AM'],a(t),'un',0);
out = datetime(a,'I','dd/MM/yyyy hh:mm:ssa','F','yyyy-MM-dd HH:mm:ss')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!