From date and time in different columns to datetime
3 ビュー (過去 30 日間)
古いコメントを表示
Hey, I have an array with date (yyyy-mm-dd) in one columns and time (hh:mm:ss) in another like this:
2017-09-29 21:00:00
2017-09-29 22:00:00
2017-09-29 23:00:00
2017-09-30 00:00:00
2017-09-30 01:00:00
2017-09-30 02:00:00
2017-09-30 03:00:00
How can I make this array into a datetime array?
1 件のコメント
Andrei Bobrov
2018 年 3 月 20 日
編集済み: Andrei Bobrov
2018 年 3 月 20 日
Please attach an example of your data (as mat-file) so that we know what type of data you are using.
採用された回答
Akira Agata
2018 年 3 月 20 日
Assuming your data is stored in CSV file like the attached, readtable function automatically recognize that 1st and 2nd column are datetime and duration. So, the following can make the datetime vector you want.
T = readtable('data1.csv');
time = T{:,1}+T{:,2};
7 件のコメント
Felix123
2020 年 7 月 21 日
@Peter Perking: can you be more specific on how to adjust these. I have not ever had a spreadsheet, where this was figured out automatically.
Peter Perkins
2020 年 7 月 28 日
It's described in the examples here:
If a recent version of readtable (NOT xlsread) can't automatically identify date columns, then there's something in the spreadsheet that's not "right". The cells in the spreadsheet may not be formatted as dates. There may be a mix of text and other things. Hard to say for sure, but recent versions of readtable are pretty good at detecting dates.
その他の回答 (1 件)
Andrei Bobrov
2018 年 3 月 20 日
編集済み: Andrei Bobrov
2018 年 3 月 20 日
datetime('2017-09-29') + hours(21:27)'
0 件のコメント
参考
カテゴリ
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!