VBA Date Time Manipulation Calendar


Example

VBA supports 2 calendars : Gregorian and Hijri

The Calendar property is used to modify or display the current calendar.

The 2 values for the Calendar are:

ValueConstantDescription
0vbCalGregGregorian calendar (default)
1vbCalHijriHijri calendar

Example

Sub CalendarExample()
    'Cache the current setting.
    Dim Cached As Integer
    Cached = Calendar

    ' Dates in Gregorian Calendar
    Calendar = vbCalGreg
    Dim Sample As Date
    'Create sample date of 2016-07-28
    Sample = DateSerial(2016, 7, 28)

    Debug.Print "Current Calendar : " & Calendar
    Debug.Print "SampleDate = " & Format$(Sample, "yyyy-mm-dd")
    
    ' Date in Hijri Calendar
    Calendar = vbCalHijri
    Debug.Print "Current Calendar : " & Calendar
    Debug.Print "SampleDate = " & Format$(Sample, "yyyy-mm-dd")
    
    'Reset VBA to cached value.
    Cached = Calendar
End Sub

This Sub prints the following ;

Current Calendar : 0
SampleDate = 2016-07-28
Current Calendar : 1
SampleDate = 1437-10-23