How can I change the input format of datetime in case that is not modifying.
22 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi guys
I have two columns in my table, Date and time
Matlab has taken Date as datetime format automatically, and the format M/d/yy does not work for that. It returns year as 0022 for Date. How can I possible change the format of date in case that it is taken by default as datetime?
attached are the screeshot of my code
another issue : as you see the order of months also is changed. for instance january comes after september instead of July. that is why isbetween does not work.
would you please guide me
'04:07:06 30/06/0022'
'04:36:51 30/06/0022'
'04:37:03 30/06/0022'
'08:16:22 30/06/0022'
'08:16:52 30/06/0022'
'09:16:52 30/06/0022'
'09:16:59 30/06/0022'
'09:26:52 30/06/0022'
'09:26:53 30/06/0022'
'09:26:59 30/06/0022'
'09:27:33 30/06/0022'
'09:27:38 30/06/0022'
'03:26:22 07/01/0022'
'03:26:53 07/01/0022'
'07:23:53 07/01/0022'
'09:13:54 07/01/0022'
'09:23:53 07/01/0022'
'09:23:53 07/01/0022'
'09:23:58 07/01/0022'
'09:24:00 07/01/0022'
'09:25:00 07/01/0022'
'09:26:00 07/01/0022'
'10:33:57 07/01/0022'
'11:16:44 07/01/0022'
'11:16:54 07/01/0022'
'11:26:44 07/01/0022'
'01:36:54 07/01/0022'
'01:52:06 07/01/0022'
'03:19:24 07/01/0022'
'03:19:54 07/01/0022'
'03:20:01 07/01/0022'
'03:20:09 07/01/0022'
2 commentaires
Steven Lord
le 1 Sep 2022
To be explicit, one thing Star Strider noted is that your data ('04:07:06 30/06/0022') doesn't match your specified date format (M/d/yy). I don't know what the 30th month of the year is. Well, I know how it could be interpreted, but more likely than not you meant the 30th day of the 6th month not the 6th day of the 30th month.
Rik
le 5 Sep 2022
Réponses (1)
Star Strider
le 1 Sep 2022
Modifié(e) : Star Strider
le 1 Sep 2022
Try this —
C = {'04:07:06 30/06/0022'
'04:36:51 30/06/0022'
'04:37:03 30/06/0022'
'08:16:22 30/06/0022'
'08:16:52 30/06/0022'
'09:16:52 30/06/0022'
'09:16:59 30/06/0022'
'09:26:52 30/06/0022'
'09:26:53 30/06/0022'
'09:26:59 30/06/0022'
'09:27:33 30/06/0022'
'09:27:38 30/06/0022'
'03:26:22 07/01/0022'
'03:26:53 07/01/0022'
'07:23:53 07/01/0022'
'09:13:54 07/01/0022'
'09:23:53 07/01/0022'
'09:23:53 07/01/0022'
'09:23:58 07/01/0022'
'09:24:00 07/01/0022'
'09:25:00 07/01/0022'
'09:26:00 07/01/0022'
'10:33:57 07/01/0022'
'11:16:44 07/01/0022'
'11:16:54 07/01/0022'
'11:26:44 07/01/0022'
'01:36:54 07/01/0022'
'01:52:06 07/01/0022'
'03:19:24 07/01/0022'
'03:19:54 07/01/0022'
'03:20:01 07/01/0022'
'03:20:09 07/01/0022'};
DT = datetime(C, 'InputFormat','HH:mm:ss dd/MM/00yy')
EDIT — (1 Sep 2022 at 12:00)
To match the original format (with changes) —
DT.Format = 'HH:mm:ss dd/MM/yyyy'
[DT_Sorted,sortidx] = sort(DT,'ascend')
Use the ‘sortidx’ vector as an index to match other variables, if necessary. (It would be the first index in a mulit-dimensional array.)
.
0 commentaires
Voir également
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!