convert dates to specific format

조회 수: 1(최근 30일)
Salma fathi
Salma fathi 2022년 7월 19일
댓글: KSSV 2022년 7월 19일
how can I change the format of the dates in the column shown in the image to the format uuuuMMddHHmm?
  댓글 수: 1
Chunru
Chunru 2022년 7월 19일
doc datetime

댓글을 달려면 로그인하십시오.

답변(2개)

Stephen23
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
N = 2.0070e+11
D = datetime(string(N),'Format','uuuuMMddHHmm')
D = datetime
200701022359
Checking:
D.Year
ans = 2007
D.Day
ans = 2
D.Minute
ans = 59
Note that you should avoid deprecated functions DATENUM, DATESTR, and DATEVEC.

KSSV
KSSV 2022년 7월 19일
t0 = datenum(today) % probably you have datenums
t0 = 738721
t1 = datetime(datestr(t0)) % convert them to datetime
t1 = datetime
19-Jul-2022
t1.Format % check the format
ans = 'dd-MMM-uuuu'
t1.Format = 'uuuuMMddHHmm' % change the format
t1 = datetime
202207190000
  댓글 수: 3
KSSV
KSSV 2022년 7월 19일
Attach your data.

댓글을 달려면 로그인하십시오.

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by