VBA/Excel/Access/Word/Date Functions/DateSerial

Материал из VB Эксперт
Версия от 12:48, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

DateSerial( returns 4

 
Sub dateDemo()
    Debug.Print DateSerial(4, 11, 23)
End Sub



DateSerial(year, month, day) returns a Variant/Date containing the date for the specified year, month, and day

 
Sub dateDemo3()
   Debug.Print DateSerial(1997, 7, 4)
End Sub



Delivery Date Maint

 
Sub Main()
    Debug.Print DeliveryDateMaint(1998,12)
End Sub
Public Function DeliveryDateMaint(intYear As Integer, intMonth As Integer)
    Dim datStart        As Date
    datStart = DateSerial(intYear, intMonth, 8)
    Select Case Weekday(datStart, vbSunday)
    Case vbSunday
        DeliveryDateMaint = datStart + 3
    Case vbMonday
        DeliveryDateMaint = datStart + 2
    Case vbTuesday
        DeliveryDateMaint = datStart + 1
    Case vbWednesday
        DeliveryDateMaint = datStart
    Case vbThursday
        DeliveryDateMaint = datStart + 6
    Case vbFriday
        DeliveryDateMaint = datStart + 5
    Case vbSaturday
        DeliveryDateMaint = datStart + 4
    End Select
End Function



Use DateSerial and Weekday

 
Public Function DeliveryDateFast(intYear As Integer, intMonth As Integer)
    Dim datStart        As Date
    datStart = DateSerial(intYear, intMonth, 8)
    DeliveryDateFast = datStart + (7 - Weekday(datStart, vbThursday))
End Function
Sub Main()
   Debug.Print DeliveryDateFast(1998,7)
End Sub