Import csv file with date and time in AM/PM format

9 vues (au cours des 30 derniers jours)
Adriel Perez Tellez
Adriel Perez Tellez le 6 Juin 2017
Commenté : Laraib Imtiaz le 19 Juin 2018
Hi everyone! I want to import some dates into Matlab but I do not seem to get the right datetime format. Normally I use Matlab's Import tool, and specify a format for my dates. My problem now is that I have the dates in AM/PM format which I am not familiar with. I have browsed through some examples without any luck. My question is: what is the proper format in order to import these dates in a datetime array?
MM/dd/yyyy HH:mm:ss ??
Some dates:
(...)
3/13/2017 11:20:00 PM
3/13/2017 11:30:00 PM
3/13/2017 11:40:00 PM
3/13/2017 11:50:00 PM
3/14/2017 12:00:00 AM
3/14/2017 12:10:00 AM
3/14/2017 12:20:00 AM
(...)
I would sincerely appreciate any help. Thanks in advance!
  1 commentaire
Stephen23
Stephen23 le 6 Juin 2017
Is it possible to change the date format to something more sensible (and universal), e.g.:

Connectez-vous pour commenter.

Réponse acceptée

per isakson
per isakson le 6 Juin 2017
Modifié(e) : per isakson le 6 Juin 2017
Try this format
>> str =
3/13/2017 11:20:00 PM
>> cac = textscan( str, '%{MM/dd/yyyy hh:mm:ss a}D', 'Delimiter',',', 'Whitespace','' )
cac =
[03/13/2017 11:20:00 PM]
The problem seems to be to convince Matlab not to interpret the spaces as deliniters
  2 commentaires
Adriel Perez Tellez
Adriel Perez Tellez le 6 Juin 2017
Ah okej. Problem solved. Thanks!
Laraib Imtiaz
Laraib Imtiaz le 19 Juin 2018
hey how?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by