convert excel dateserial number to matlab serial number

1 回表示 (過去 30 日間)
AA
AA 2017 年 3 月 17 日
コメント済み: Star Strider 2017 年 3 月 18 日
hi guys, i have an excel file that displays the following dateserial number 19300101. this includes the date as well as time. how can i convert it within matlab to a matlab dateserial number?

回答 (1 件)

Star Strider
Star Strider 2017 年 3 月 17 日
If you have R2014b or later, you have the datetime functions.
X = 19300101
t = datetime(X,'ConvertFrom','excel')
X =
19300101
t =
datetime
17-Nov-54741 00:00:00
I suspect that ‘X’ is not an Excel serial date but a date vector of some other format.
  2 件のコメント
Star Strider
Star Strider 2017 年 3 月 18 日
AA’s ‘Answer’ moved here
no the format is yyyyMMdd HHmmss
Star Strider
Star Strider 2017 年 3 月 18 日
You have to supply the hour, minute, and second values as well. If they are strings, use them directly in datenum. If they are numbers, you must first convert them to strings (easiest with the sprintf function):
dn = datenum(sprintf('%08d %06d', [19300101 000000]), 'yyyyMMdd HHmmss')
dn =
704888.000694444
You must supply the date and time (strings or vectors) to match your format string.
You can do the same sort of conversion with datetime objects. I used datenum here because everyone has it.

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

カテゴリ

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