Manage Learn to apply best practices and optimize your operations.

# Two date functions

## This tip describes two date functions.

Here are 2 general-purpose functions to have in your toolbox:
DaysBetweenThenAndNow takes in a date and returns the number of days between that date and now.
DaysBetweenTwoDates takes in 2 dates and returns the difference in days.

I use them a lot in reporting modules. In my tests they work back to 1936.

```Function DaysBetweenThenAndNow
(ThenDate As Variant) As Integer
' This function takes a date and
compares it to the current date
' and returns the difference in days
' if there is an error like the date
being passed is invalid
'  it will return -999 as its value
'  To use this function in your script:
'   daysdifference =
DaysBetweenThenAndNow (doc.SomeDate(0))
'   where doc.SomeDate(0)
is a date/time field
On Error Goto errorstate
'create varaiable to hold the calculations
Dim diff As Double
'get the current date
Dim datetime As New NotesDateTime ("")
Call datetime.SetNow()
'get rid of the time part so that we
are only comparing whole dates
Call datetime.SetAnyTime
'get the date of the passed in value
Dim EarlierDate As New NotesDateTime
(ThenDate)
'get the difference between the two dates
in seconds
diff = datetime.TimeDifference (EarlierDate)
' divide by 86400 (the number of
seconds in day) to get the number
of days and return the value
DaysBetweenThenAndNow = diff/86400
Exit Function
errorstate:
DaysBetweenThenAndNow = -999
End Function

Function DaysBetweenTwoDates
(earlierdate As Variant, laterdate As Variant)
As Integer
' This function takes 2 dates and
compares them
' it returns the difference in days
' if there is an error like the date
being passed is invalid
'  it will return -999 as its value
'  To use this function in your script:
'  daysdifference = DaysBetweenThenAndNow
(doc.EarlierDate(0), doc.LaterDate(0))
'   where doc.EarlierDate(0)and
docLaterDate(0) are date/time fields
On Error Goto errorstate
'create varaiable to hold the calculations
Dim diff As Double
'get the passed in values
Dim EarlyDate As New NotesDateTime
(earlierdate)
Dim LateDate As New NotesDateTime (laterdate)
'get rid of the time part so that we are only
comparing whole dates
'comment these lines out if the dates
do NOT have time components
Call EarlyDate.SetAnyTime
Call LateDate.SetAnyTime
'get the difference in seconds
diff = LateDate.TimeDifference (EarlyDate)
'divide by the number of seconds in
day and return the value
DaysBetweenTwoDates = diff/86400
Exit Function
'this is where we go when things go wrong
errorstate:
```

#### Start the conversation

Send me notifications when other members comment.

## SearchWindowsServer

• ### December Patch Tuesday resolves Windows zero-day

Microsoft delivers the final batch of security fixes for the year with a Windows zero-day vulnerability getting top billing for ...

Microsoft put its branding on a relatively new hyper-converged infrastructure offering that capitalizes on the software-defined ...

• ### How to manage Exchange hybrid mail flow rules

Duplicating your existing transport rule collection won't work when you move to an Exchange hybrid deployment. Learn how to set ...

## Search400

• ### iSeries tutorials

Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

• ### V6R1 upgrade planning checklist

When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

• ### Connecting multiple iSeries systems through DDM

Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

## SearchDataCenter

• ### Refresh your data center cooling lexicon

As the data center industry moves to improve energy efficiency, refresh your knowledge on the available cooling technology and ...

• ### Comparing Linux distributions: Red Hat vs. Ubuntu

Before selecting a Linux distribution, compare Red Hat Enterprise Linux and Ubuntu when it comes to features, ease of use, ...

• ### Get eco-friendly with LEED data center certification

The U.S. Green Building Council helps companies make existing and new data centers eco-friendly. HVAC, lighting and monitoring ...

## SearchContentManagement

• ### DNA as a content storage device is closer than you think

Storing content in DNA may one day be possible, but today, it's neither practical nor cost-effective. Here's where this ...

• ### Acquia acquisition of AgilOne CDP signals CX platform expansion

Acquia's acquisition of AgilOne, a customer data platform specializing in analytics, shows it's serious about competing against ...

• ### Personalization engines help engage and retain customers

Content personalization is essential to getting the right material to the right customers. Here are some personalization engines ...

Close