convert dates to specific format
조회 수: 2 (최근 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!