how to combine a date and corresponding time column imported from a .CSV file.

8 vues (au cours des 30 derniers jours)
Srini Lakshmanan
Srini Lakshmanan le 14 Nov 2015
for example one column has 13/11/2015 and another column has HH.mm.ss in 5 min interval for 24 hours.I want to merge this two into one format dd-mm-yy-HH-mm-ss. note: both are already in datatime type.
  1 commentaire
Stephen23
Stephen23 le 14 Nov 2015
Modifié(e) : Stephen23 le 14 Nov 2015
There are many advantages to using an ISO 8601 date format, particularly that a lexicographical sort of the strings puts the dates into the correct order. Try my FEX submissions for experimenting with ISO 8601 date strings and timestamps:

Connectez-vous pour commenter.

Réponses (1)

Peter Perkins
Peter Perkins le 19 Nov 2015
Srini, it sounds like you've imported the file OK, you just need to combine the two pieces.
Probably you used a format like '%{dd/MM/yyyy}D%{HH.mm.ss}D' t read those two columns in the file into datetime arrays (maybe in a table?). As you may have discovered, the first (call it d1) will have the time portions all set to 00:00:00, and the second (call it d2) will have the date portion all set to the current date. They may not display those parts, but they're there.
So try this:
d = d1 + timeofday(d2);
d.Format = 'dd-mm-yy-HH-mm-ss'
That's kind of a funny choice of formats, but it is legal.
Hope this helps.

Catégories

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

Community Treasure Hunt

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

Start Hunting!

Translated by