Why does the date returns “31-12-1899” when 1 is passed to it?

后端 未结 2 1750
傲寒
傲寒 2021-02-13 14:23

I am using windows 10 OS excel 13 so in the below code 1 should return 1/1/1900 right ? below it doesn\'t why.

On this question OP pas

2条回答
  •  臣服心动
    2021-02-13 15:04

    It is just the worksheet itself. Or to be correct: The worksheet-functionality!

    Quick test:

    ?cdate(1)
    1899-12-31 
    ?format(1,"YYYY-MM-DD")
    1899-12-31
    ?worksheetfunction.Text(1,"YYYY-MM-DD")
    1900-01-01
    

    But going for todays date does not show this gap:

    ?clng(now)
     42463 
    ?worksheetfunction.Text(now,"0")
    42463
    

    That shows that somewhere between 1 and 42463 is a gap (the quick lotus check shows it:

    ?cdate(60) & " --- " & cdate(61)
    1900-02-28 --- 1900-03-01
    ?format(60,"YYYY-MM-DD") & " --- " & format(61,"YYYY-MM-DD")
    1900-02-28 --- 1900-03-01
    ?worksheetfunction.Text(60,"YYYY-MM-DD") & " --- " & worksheetfunction.Text(61,"YYYY-MM-DD")
    1900-02-29 --- 1900-03-01
    

    Just one last test to show it again:

    ?format("1900-02-28","0") & " --- " & format("1900-03-01","0")
    60 --- 61
    ?worksheetfunction.Text("1900-02-28","0") & " --- " & worksheetfunction.Text("1900-03-01","0")
    59 --- 61
    

    starting with 61, there is simply now difference in numbers. But the Lotus-Bug adds the 1900-02-29 for "compatibility".

    Also: that is a "feature" for excel and has nothing to do with basic, vbscript, vba.......... All other programs work in the correct way and it would get lots of trouble if VBA would not. So for "compatibility" the VBA in excel just does it in the correct way ;)

提交回复
热议问题