【VBA】Get the year,month,day from the date

You can get
the “year, month, day” from the date!

Use the following function:
 year function
 Month function
 Day function

PR

VBA Code

As an example, Get Today’s year, month, day.

Option Explicit

Sub sampleProc()
    
    Dim today As Variant
    Dim yyyy As Integer
    Dim mm As Integer
    Dim dd As Integer
    
    'Get Today's date
    today = Date
    
    'Get Today's year, month, day
    yyyy = Year(today)
    mm = Month(today)
    dd = Day(today)
    
    MsgBox ("year  : " & yyyy & vbCrLf & _
            "month : " & mm & vbCrLf & _
            "day   : " & dd)
    
End Sub

Get Today’s date(Line 11).

Get Today’s year, month, day(Line 18~20).

PR

Result

You got the “year, month, day” from the date.

Result
Result
PR

FYI

For more information about following, see the following official online manual:

●Year function


●Month function


●Day function

タイトルとURLをコピーしました