VBA/Excel/Access/Word/Date Functions/DateAdd

Материал из VB Эксперт
Перейти к: навигация, поиск

Add value to Date

Sub AddADay()
    Dim dtInitialDate As Date
    dtInitialDate = DateAdd("d", 1, dtInitialDate)
    Debug.Print dtInitialDate
End Sub

DateAdd(interval, number, date) returns a Variant/Date containing the date of the specified interval after the specified date

Sub dateDemo2()
    Debug.Print DateAdd("m", 1, "6/3/06"); returns; 7 / 3 / 2006#
End Sub

DateAdd returns the result of adding or subtracting a specified period of time to a date:

Sub DateAddExample()
    Debug.Print DateAdd("d", 3, Now)
    "Today plus 3 days
    Debug.Print DateAdd("m", 3, Now)
    "Today plus 3 months
    Debug.Print DateAdd("yyyy", 3, Now)
    "Today plus 3 years
    Debug.Print DateAdd("q", 3, Now)
    "Today plus 3 quarters
    Debug.Print DateAdd("ww", 3, Now)
    "Today plus 3 weeks
    Debug.Print DateAdd("ww", -3, Now)
    "Today minus 3 weeks
End Sub