pha*_*han 1 excel datetime vba
我有一个8位数字,告诉我日期,YYYYMMDD.如何将此数字转换为Excel将识别为日期的日期.
我们假设单元格A1中有20120229 ...我该怎么办?
既然你标记了这个问题VBA,我假设你想要一个VBA的答案,所以你走了:
Dim l As Long
Dim s As String
Dim d As Date
l = Range("A1").Value ' 20120229
' convert it to a string
s = CStr(l)
' can now use string functions to parse it
d = DateSerial(CInt(Left(s, 4)), CInt(Mid(s, 5, 2)), CInt(Right(s, 2)))
' d is now 29 Feb 2012
' write it back to the sheet
Range("A2").Value = d
Run Code Online (Sandbox Code Playgroud)
使用以下公式:=DATE(LEFT(A1,4),MID(A1,5,2),RIGHT(A1,2))其中A1是单元格坐标。
| 归档时间: |
|
| 查看次数: |
28582 次 |
| 最近记录: |