日付処理:文字列から日付へ変換、年月日の取得(1桁、2桁の取得結果)

嚯嚯go發表於2024-04-24
Private Sub CommandButton1_Click()

    Dim strTaisyo, date1, mydate, warekiNen, yy, mm, dd
    
    strTaisyo = "20240401"
    date1 = Format(strTaisyo, "####/##/##")
    mydate = CDate(date1)
    
    ActiveSheet.Cells(2, 3).Value = "date1=" & date1
    ActiveSheet.Cells(3, 3).Value = "mydate=" & mydate
    
    yy = Year(mydate)
    mm = Month(mydate)
    dd = Day(mydate)
    ActiveSheet.Cells(4, 3).Value = "yy=" & yy & " mm=" & mm & " dd=" & dd
    
    yy = Format(mydate, "YYYY")
    mm = Format(mydate, "mm")
    dd = Format(mydate, "dd")
    ActiveSheet.Cells(5, 3).Value = "yy=" & yy & " mm=" & mm & " dd=" & dd
    

End Sub

實行結果:

相關文章