Source code for Issue Number 53

Copyright 1997-2000 by C&D Programming Corp. All Rights Reserved. Source code may not be reproduced except for use in a compiled executable. All rights reserved. If you would like to reprint any or all of this code please email us at info@codeoftheweek.com

Code of the Week Home


Source Code

Just paste this source code into a module called basDates and include it in your project.

'----------------------------------------------------------------------
'
'   Module Name:    basDates
'   Written By:     C&D Programming Corp.
'   Create Date:    8/98
'   Copyright:      Copyright 1998 by C&D Programming Corp.  Source
'                   code may not be reproduced except for use in a
'                   compiled executable.  All rights reserved.  If
'                   you would like to reprint any or all of this
'                   code please email us at info@codeoftheweek.com
'----------------------------------------------------------------------
Option Explicit

Public Function DaysUntil(dFutureDate As Date) As Long
    If dFutureDate < Now Then
        DaysUntil = 0
    Else
        DaysUntil = DateDiff("d", Now, dFutureDate)
    End If
End Function

Public Function DayOfYear() As Long
    ' the 1/1/ is a trick to get the first day of the year.
    ' we need to add one to make sure we include the first day
    ' in our count.
    DayOfYear = DateDiff("y", "1/1/" & Year(Now), Now) + 1
End Function

Public Function DaysPast(dPastDate As Date) As Long
    If dPastDate > Now Then
        DaysPast = 0
    Else
        DaysPast = DateDiff("d", dPastDate, Now)
    End If
End Function