Excel datevalue

2020-04-17 07:23发布

How do I convert a date string 2019-06-20T00:00:00+01:00 to an Excel date? DATEVALUE returns #Value when I try this in Excel.

The date string comes from C# DateTime ToShortDateString()

标签: c# excel date
2条回答
狗以群分
2楼-- · 2020-04-17 07:53

Instead of ToShortDateString() use ToOADate().

Format the cell as Date and you should be all set.

查看更多
成全新的幸福
3楼-- · 2020-04-17 07:53

In Excel you could just take everything to the left of the T character. If that date string was in cell A1 then:

=DATEVALUE(LEFT(A1,FIND("T",A1)-1))

Alternatively in VBA if the date string was stored in a variable called sFoo:

CDate(Left$(sFoo,Instr(sFoo,"T")-1))
查看更多
登录 后发表回答