No InputFormat 'YYMMDD' found for datetime

Is there a way to transform '240331' into '31 March 2024' ?
The following does not work:
datetime('240331',InputFormat,'YYMMDD')
Unrecognized function or variable 'InputFormat'.

2 件のコメント

Stephen23
Stephen23 2024 年 5 月 2 日
編集済み: Stephen23 2024 年 5 月 2 日
"No InputFormat 'YYMMDD' found for datetime"
Character case matters!
"Is there a way to transform '240331' into '31 March 2024' ?"
datetime('240331', 'InputFormat','yyMMdd', 'Format','dd MMMM yyyy')
ans = datetime
31 March 2024
Sim
Sim 2024 年 5 月 2 日
Thanks a lot @Stephen23!! :-)

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

 採用された回答

Steven Lord
Steven Lord 2024 年 5 月 2 日

1 投票

Either leave the quotes off but use == (if you're using a sufficiently recent release) or add quotes. You will need to adjust your format specifier, though.
datetime('240331',InputFormat = 'yyMMdd')
ans = datetime
31-Mar-2024
datetime('240331','InputFormat','yyMMdd')
ans = datetime
31-Mar-2024
You need to use 'yy' instead of 'YY' and 'dd' instead of 'DD'.
datetime('240331',InputFormat = 'YYMMDD')
Error using datetime (line 669)
The format 'YYMMDD' contains an unsupported symbol: 'Y'. See the datetime.Format property for a complete description of the identifiers used in datetime formats.

3 件のコメント

Sim
Sim 2024 年 5 月 2 日
編集済み: Sim 2024 年 5 月 2 日
Many thanks to both of you @Steven Lord and @Star Strider!
Very appreciated! ...I thought that the input format was not case sensitive... :-)
Please, bear in mind that I would have accepted both of your answers, if I could! :-) :-)
Steven Lord
Steven Lord 2024 年 5 月 2 日
Since the format needs to have ways to represent both the Month component and the minute component of a datetime, the most natural representation IMO is for M to be case sensitive. [This was not a choice MathWorks made; that's part of the Unicode Locale Data Markup Language specification linked from the documentation page I reference below. I believe the LDML uses the symbols from ISO standard 8601.]
The table in the entry for the Format property on the datetime documentation page lists the character and character sequences that have special meanings when used in a format specifier (either the InputFormat name-value argument to the constructor or the Format property which can be set in the constructor or after the object has been created.)
Sim
Sim 2024 年 5 月 2 日
Wow, nice explanation, thanks! I will read about the document page :-)

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

その他の回答 (0 件)

カテゴリ

質問済み:

Sim
2024 年 5 月 2 日

編集済み:

2024 年 5 月 2 日

Community Treasure Hunt

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

Start Hunting!

Translated by