datestr generating different string

I have an array with days, months and years. This is my string
[myd '/' mym '/' myy]
ans =
20/01/2014
But datestr generates this
datestr([myd '/' mym '/' myy])
ans =
06-Jul-0025
Any clue?
Thanks

 採用された回答

Chad Greene
Chad Greene 2021 年 5 月 1 日

0 投票

How about
myy = 2014;
mym = 1;
myd = 20;
datestr(datenum(myy,mym,myd),'dd/mm/yyyy')
ans = '20/01/2014'

3 件のコメント

Simon Lind
Simon Lind 2021 年 5 月 1 日
myy, mym and myd are 'char'
I did
mystr = datestr(datenum(str2num(myy),str2num(mym),str2num(myd)),'dd/mm/yyyy')
ans =
21/03/2014
but
datevec(mystr)
ans =
26 9 4 0 0 0
Chad Greene
Chad Greene 2021 年 5 月 1 日
How's this?
datestr(datenum(string([myd '/' mym '/' myy]),'dd/mm/yyyy'))
Simon Lind
Simon Lind 2021 年 5 月 1 日
I just removed the 'string' and now it works
datestr(datenum(([myd '/' mym '/' myy]),'dd/mm/yyyy'))
thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

製品

リリース

R2016b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by