merging date and time columns in a timetable

8 vues (au cours des 30 derniers jours)
Akram Hussein
Akram Hussein le 4 Juil 2020
I have .csv file with two separate columns one for date and one for time. I am trying to import them both in a single field in a timetable and use them as rowtimes. Any pointers?
Date Time
____ ______
06/07/2020 17:00:01
06/07/2020 17:00:02
06/07/2020 17:00:03

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Juil 2020
tt = table2timetable( YourTable, 'RowTimes', datetime(YourTable.Date) + duration(YourTable.Time) );

Plus de réponses (1)

Akram Hussein
Akram Hussein le 4 Juil 2020
Thank You. I had to do just a tweak in formatting to make it work. So posting the code for others. The time format i was using was 'MM/dd/yyyy HH:mm:ss' and had to be specified. Further t.Date is of type datetime and t.Time is of type duration
t = readtable(filename);
tt = table2timetable( t, 'RowTimes', datetime(t.Date + t.Time,'Format','MM/dd/yyyy HH:mm:ss') );

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by