# Datenum with a.m. and p.m.

8 vues (au cours des 30 derniers jours)
Brenton Hirao le 15 Nov 2019
Commenté : Adam Danz le 15 Nov 2019
I have a data set with timestamps:
'11/5/2019 12 a.m. EST'
...
'11/10/2019 1 p.m. EST'
How can I convert these timestamps into a vector of date numbers?
thanks for the help.
##### 4 commentairesAfficher 2 commentaires plus anciensMasquer 2 commentaires plus anciens
Brenton Hirao le 15 Nov 2019
Walter Robinson, the periods are part of the text. The data only contains EST.
Adam Danz le 15 Nov 2019
So you're converting from strings to datenum?
https://www.mathworks.com/help/matlab/ref/datenum.html
It might be necessary to remove the dots first using strrep but maybe not (my machine has been shut down for the night).

Connectez-vous pour commenter.

### Réponse acceptée

Shubham Gupta le 15 Nov 2019
Assuming there is ".m. EST" attached to each "timestamp" at the end. You can follow the steps:
Step-1 Replace ".m. EST" to just "m" (Hint : regexprep)
Step-2 Convert the output into the date numbers (Hint: datenum)
You should get the output with date numbers in a array. (Not sure what do mean by "continuous"?)
##### 2 commentairesAfficher AucuneMasquer Aucune
Walter Roberson le 15 Nov 2019
S = '11/5/2019 12 a.m. EST';
temp = regexprep(S, '\.m\.', 'm');
t = datetime(temp, 'Inputformat', 'd/M/yyyy h a z', 'TimeZone', 'America/Chicago');
The above will have "eastern time" as the attached timezone. You can switch it to EST but you will get a warning,
Warning: 'EST' specifies a time zone with a fixed offset from UTC, -05:00. This zone does not follow daylight saving time, and so may give unexpected results. See the datetime.TimeZone property for details about specifying time zones.
Adam Danz le 15 Nov 2019
Instead of the regexprep() you could also do
temp = strrep(S,'.','');

Connectez-vous pour commenter.

### 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