Converting numeric elements to date

113 ビュー (過去 30 日間)
Milad Naderloo
Milad Naderloo 2020 年 9 月 30 日
コメント済み: Milad Naderloo 2020 年 9 月 30 日
I have converted date to serial number:
A= 10-Jan-2000
D = datenum(A)
D = 730495
And after doing some operation, I want to change (D) it back to the date format. But could not.
Is there any function to convert serial number to date format?

採用された回答

Steven Lord
Steven Lord 2020 年 9 月 30 日
Depending what operations you need to perform, you may be able to keep your data as a datetime array without converting it to serial date numbers. But if you do, datetime can convert serial date numbers into a datetime array.
>> dt = datetime('now')
dt =
datetime
30-Sep-2020 09:48:21
>> sdn = datenum(dt)
sdn =
7.3806e+05
>> dt2 = datetime(sdn, 'ConvertFrom', 'datenum')
dt2 =
datetime
30-Sep-2020 09:48:21
As an example of some operations defined on datetime arrays, you can perform date and time arithmetic using datetime and duration arrays.
>> dt3 = dt + hours(1) + minutes(2) + seconds(3) % datetime + duration = datetime
dt3 =
datetime
30-Sep-2020 10:50:24
>> du = dt3 - dt2 % datetime - datetime = duration
du =
duration
01:02:03
  1 件のコメント
Milad Naderloo
Milad Naderloo 2020 年 9 月 30 日
I apperciate, your suggestion works well

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

その他の回答 (1 件)

Ameer Hamza
Ameer Hamza 2020 年 9 月 30 日
編集済み: Ameer Hamza 2020 年 9 月 30 日
A = '10-Jan-2000';
D = datenum(A);
D = D + 10;
B = datestr(D);
Result
>> B
B =
'20-Jan-2000'
  1 件のコメント
Milad Naderloo
Milad Naderloo 2020 年 9 月 30 日
Thank you so much!

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

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by