日期到文本,反之亦然 excel

Date to text and vice versa in excel

我看到 excel 用特定的序列号标识日期。例如:

    09/07/2018 = 43290
    10/07/2018 = 43291

我知道我们使用 DATEVALUEVALUETEXT 函数在这些类型之间进行转换。

但是这种转换背后的逻辑是什么?为什么 4329009/07/2018

此外,如果我在 dataframe (Python) 中有这些日期的数字格式列表,我如何将这些数字转换为日期格式?

与时间类似,我看到小数值代替了常规时间格式。这些时间转换背后的逻辑是什么?

评论中给出的以下问题提供了信息,但没有回答我关于 Date 和 Text 格式之间转换背后的逻辑的问题: convert numerical representation of date (excel format) to python date and time, then split them into two seperate dataframe columns in pandas

它只是自 1 月 1 日st 1900 年以来的天数(如果谈论日期和时间,则为天数的一部分):

The DATEVALUE function converts a date that is stored as text to a serial number that Excel recognizes as a date. For example, the formula =DATEVALUE("1/1/2008") returns 39448, the serial number of the date 1/1/2008. Remember, though, that your computer's system date setting may cause the results of a DATEVALUE function to vary from this example
...
Excel stores dates as sequential serial numbers so that they can be used in calculations. By default, January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,447 days after January 1, 1900.

来自 DATEVALUE docs

if I have a list of these dates in the number format in a dataframe (Python), how can I convert this number to the date format?

因为我们知道这个数字代表自 1900 年 1 月 1 日以来的天数,所以它可以很容易地转换为日期:

from datetime import datetime, timedelta

day_number = 43290

print(datetime(1900, 1, 1) + timedelta(days=day_number - 2))
#  2018-07-09 00:00:00                                   ^ subtracting 2 because 1/1/1900 is
#                                                          "day 1", not "day 0"

但是 pd.read_excel 应该能够自动处理。