ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ½Ð±Ð¤@­Ó¦Û¼gªº¤é´ÁÂ૬³B²z

[µo°Ý] ½Ð±Ð¤@­Ó¦Û¼gªº¤é´ÁÂ૬³B²z

½Ð±Ð¤@­Ó¦Û¼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
  1. Sub Test()
  2.     Dim today As String

  3.     today = DateToStr(Date, "/")
  4.     Cells(1, 1).Value = today
  5. End Sub

  6. Function DateToStr(cvDate, delimeter)
  7.     Dim yr, mm, dd, i, k
  8.    
  9.     If (Len(cvDate) < 8 Or Mid(cvDate, 5, 1) <> delimeter) Then
  10.         DateToStr = ""
  11.         Exit Function
  12.     End If
  13.    
  14.     yr = Mid(cvDate, 1, 4)
  15.     mm = Mid(cvDate, 6, 2)
  16.     If (Mid(mm, 2, 1) = delimeter) Then mm = "0" + Mid(mm, 1, 1): dd = Mid(cvDate, 8) Else dd = Mid(cvDate, 9)
  17.     If (Len(dd) = 1) Then dd = "0" + dd
  18.    
  19.     DateToStr = yr + mm + dd

  20.     k = 0
  21.     If (Len(DateToStr) > 0) Then
  22.         For i = 1 To Len(DateToStr)
  23.             If (Mid(DateToStr, i, 1) < "0" Or Mid(DateToStr, i, 1) > "9") Then k = 1
  24.         Next i
  25.     End If
  26.    
  27.     If (k = 1) Then DateToStr = ""
  28. End Function
½Æ»s¥N½X

Sub Test()
   [a1] = Format(Date, "yyyymmdd")
End Sub

TOP

¦^´_ 2# oobird

­ì¨Ó³o»ò²³æ°Õ¡I
¤£ÁA¸Ñ VBA ¥Îªkªº¤H´N¬O¥u·|¤gªk·Ò¿û¡A
·PÁ±zªº«ü¾É¡I

TOP

Àx¦s®æ®æ¦¡¦Û­q­×§ï¤]¬O¥i¥Hªº

TOP

ª½±µ¦bÀx¦s®æ®æ¦¡¦Û­q¦¨
yyyymmdd
egg

TOP

¦^´_ 5# eggdd
¦hÁ§iª¾¡A §Ú¬OÀ³¥Î¦bµ{¦¡¤º¡A ©Ò¥H«á§ï¥Î¤F Format(Date, "yyyymmdd") ªº³B²z¡C
ÁÂÁ±z¡I

TOP

        ÀR«ä¦Û¦b : ¡i®É¶¡¦pÆp¥Û¡j®É¶¡¹ï¤@­Ó¦³´¼¼zªº¤H¦Ó¨¥¡A´N¦pÆp¥Û¯ë¬Ã¶Q¡F¦ý¹ï·M¤H¨Ó»¡¡A«o¹³¬O¤@§âªd¤g¡A¤@ÂI»ù­È¤]¨S¦³¡C
ªð¦^¦Cªí ¤W¤@¥DÃD