½Ð±Ð¤@Ó¦Û¼gªº¤é´ÁÂ૬³B²z¡C
»¡©ú¡G °²³]
1). Date ¨ç¼Æªº¨ú¦^Ȭ° "2012/3/8"¡A«h¤U¦C DateToStr ¨ç¼Æ·|¦Û°Ê±N¥¦Âন "20120308"
2). Date ¨ç¼Æªº¨ú¦^Ȭ° "2012/3/18"¡A«h¤U¦C DateToStr ¨ç¼Æ·|¦Û°Ê±N¥¦Âন "20120318"
3). Date ¨ç¼Æªº¨ú¦^Ȭ° "2012/10/8"¡A«h¤U¦C DateToStr ¨ç¼Æ·|¦Û°Ê±N¥¦Âন "20121008"
4). Date ¨ç¼Æªº¨ú¦^Ȭ° "2012/10/10"¡A«h¤U¦C DateToStr ¨ç¼Æ·|¦Û°Ê±N¥¦Âন "20121010"
°£¤F¥H¤U§Ú¦Û¼gªº Function ¥~¡A ½Ð°ÝÁÙ¦³¨S¦³§ó¦nªº Function ªí¹F¤è¦¡¤Î¼gªk¡H
ÁÂÁ¦U¦ì¥ý¶i«ü¾É¡I- Sub Test()
- Dim today As String
- today = DateToStr(Date, "/")
- Cells(1, 1).Value = today
- End Sub
- Function DateToStr(cvDate, delimeter)
- Dim yr, mm, dd, i, k
-
- If (Len(cvDate) < 8 Or Mid(cvDate, 5, 1) <> delimeter) Then
- DateToStr = ""
- Exit Function
- End If
-
- yr = Mid(cvDate, 1, 4)
- mm = Mid(cvDate, 6, 2)
- If (Mid(mm, 2, 1) = delimeter) Then mm = "0" + Mid(mm, 1, 1): dd = Mid(cvDate, 8) Else dd = Mid(cvDate, 9)
- If (Len(dd) = 1) Then dd = "0" + dd
-
- DateToStr = yr + mm + dd
- k = 0
- If (Len(DateToStr) > 0) Then
- For i = 1 To Len(DateToStr)
- If (Mid(DateToStr, i, 1) < "0" Or Mid(DateToStr, i, 1) > "9") Then k = 1
- Next i
- End If
-
- If (k = 1) Then DateToStr = ""
- End Function
½Æ»s¥N½X |