Dates in LS-agent

Hi all!I’m new with LS and I have a problem.

I have a view where to agent gets docs, now it takes per day. I should make it to read docs for 5 days backwords and now I have to make it show only one date if there is multiple docs for that day. Understandable?

It´s like gatecorized by date but how in LS?

thx for any help

Subject: Dates in LS-agent

There are many ways to achieve what you describe. I would not use a categorized view. I would do one of two things – either use a full-text search to get a collection or simply iterate through a sorted view to get the ones you want.

I might approach it like this. Have a view sorted by the date-field of interest, get first document, do a date comparison, get next doc, compare date, …

continue until you hit one that is more than 5 days old.

I have included two functions below that might help. You can use DaysBetweenThenAndNow for a simple comparison.

http://searchdomino.techtarget.com/tip/1,289483,sid4_gci899579,00.html?FromTaxonomy=%2Fpr%2F283841

elvis brown 05 May 2003

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

'in case of errors this is where we jump to

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:

Subject: 1936 version of Notes?

:slight_smile: Personally, I didn’t do much testing back during 1936.