Change Date Formatting for Excel in Matlab

2 ビュー (過去 30 日間)
Devidutta
Devidutta 2025 年 1 月 3 日
コメント済み: Devidutta 2025 年 1 月 6 日
Hi community,
I am working on script to read from file and save to Excel, currently have dates in form of '10/12/2024; 10:58:49'.
I want to use the datestr function to get it in a readable way like '10-Dec-2024 10:58:49'
Can someone help me in this ? I am using MATLAB R2024a
Thanks

採用された回答

Pratyush Swain
Pratyush Swain 2025 年 1 月 3 日
編集済み: Pratyush Swain 2025 年 1 月 3 日
Hi Devidutta,
The 'datestr' function is not recommended to be used since R2022b as mentioned here: https://www.mathworks.com/help/matlab/ref/datetime.datestr.html
Alternatively you can use this following approach to acheive your desired date & time format:
% Original date string, separated by semicolon
dateStr = '10/12/2024; 10:58:49';
% Convert to datetime
dt = datetime(dateStr, 'InputFormat', 'dd/MM/yyyy; HH:mm:ss');
% Format the date using the datetime display format
dt.Format = 'dd-MMM-yyyy HH:mm:ss';
% Display the result
disp(char(dt));
10-Dec-2024 10:58:49
For more information on 'datetime' function, please refer to https://www.mathworks.com/help/matlab/ref/datetime.html
Hope this helps.
  1 件のコメント
Devidutta
Devidutta 2025 年 1 月 6 日
Thanks, This was really helpful!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import from MATLAB についてさらに検索

タグ

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by