convert dates to specific format
3 次查看(过去 30 天)
显示 更早的评论
how can I change the format of the dates in the column shown in the image to the format uuuuMMddHHmm?
回答(2 个)
Stephen23
2022-7-19
编辑:Stephen23
2022-7-19
My guess is that you have unfortunately stored each date as one numeric value, whose digits just happen to coincide with the date units' digits. This is rather a misuse of numerics, and is best fixed by importing that data correctly, rather than trying to "fix" it later. But you can convert to a proper DATETIME object if required:
N = 200701022359 % ugh
D = datetime(string(N),'Format','uuuuMMddHHmm')
Checking:
D.Year
D.Day
D.Minute
Note that you should avoid deprecated functions DATENUM, DATESTR, and DATEVEC.
0 个评论
KSSV
2022-7-19
t0 = datenum(today) % probably you have datenums
t1 = datetime(datestr(t0)) % convert them to datetime
t1.Format % check the format
t1.Format = 'uuuuMMddHHmm' % change the format
3 个评论
Stephen23
2022-7-19
"Any advice how to fix it?"
- understand how your date is currently stored.
- use that knowledge to select a suitable tool to convert it to DATETIME.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!