need to merge date and time in 5 separate columns in to two and then one

2 ビュー (過去 30 日間)
Amila
Amila 2022 年 9 月 15 日
コメント済み: Eric Sofen 2022 年 9 月 16 日
I have date and time in 5 columns like
YYYY
MM
DD
HH
mm
I wanted to get two colums as date and time
YYYYMMDD and
HHmm
Then a third column like
YYYYMMDDHHmm
Can you please guid im beginner, Thank you verry mutch

採用された回答

Walter Roberson
Walter Roberson 2022 年 9 月 15 日
dt = datetime(YourTable.YYYY, YourTable.MM, YourTable.DD, YourTable.HH, YourTable.mm, 0);
newTable.YYYYMMDD = dt; newTable.YYYYMMDD.Format = 'uuuuMMdd';
newTable.HHmm = dt; newTable.HHmm.Format = 'HH:mm';
newtable.YYYYMMDDHHmm = dt; newtable.YYYYMMDDHHmm.Format = 'uuuuMMddHHmm';
This assumes that you would be okay with the table containing the same data for the three columns as long as what is displayed is in the format you indicated. If the entries have to contain only the data you indicate then the process would be different. Would the entries have to be numeric? Such as 202209121536 ?
  2 件のコメント
Amila
Amila 2022 年 9 月 16 日
Thank you very mutch with my data sheet i have used this with some modifications cord I used is
dt2 = datetime(Result2(:,1), Result2(:,2), Result2(:,3), Result2(:,4), Result2(:,5), 0);
Thank you verry much !
Eric Sofen
Eric Sofen 2022 年 9 月 16 日
Depending on what you want to do with the HHmm data, you may want to use the timeofday function on the datetime to get a duration in hours and minutes from midnight of the current day, rather than just changing the format.
newTable.HHmmdur = timeofday(dt)

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

その他の回答 (0 件)

カテゴリ

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