What am I doing wrong with this LS TimeDifference. I’m read so many posts that I’m confused! Thanks for help…
Dim Todaydate As NotesDateTime
Dim DocCreateddate As NotesDateTime
Dim Howold As Long
Set Todaydate = New NotesDateTime (“Today”)
Set DocCreateddate = New NotesDateTime (DocOne.FieldGetText(“docdate”))
Howold = DocCreateddate.TimeDifference(Todaydate)/86400
If Howold > 5 & DocOne.ccloseddate(0) = “” Then
Subject: TimeDifference Question
Doesn’t appear to be anything wrong with it at first glance but maybe you are failing on the field named
ccloseddate
instead of
closeddate
Edited: You also used the & operator when you probably meant to use And
Subject: RE: TimeDifference Question
The field name is correct…that’s exactly what is on the form.
I’m getting type mismatch on this line:
Set DocCreateddate = New NotesDateTime (DocOne.FieldGetText(“docdate”))
So if the document is > 5 days old and field ccloseddate is null then do something…
First time working with this time difference…looked to the correct way of doing this in LS.
Any suggestions? Thanks!
Subject: RE: TimeDifference Question
I had assumed that DocOne was set to a document, but maybe it’s not - have you checked that?
Subject: RE: TimeDifference Question
Is DocOne a NotesDocument or NotesUIDocument? FieldGetText may only be used on a NotesUIDocument.
Subject: RE: TimeDifference Question
Is DocOne a NotesDocument or NotesUIDocument?
DonOne is a NotesDocument.
Subject: RE: TimeDifference Question
Since, as has already been noted, FieldGetText is not a method of NotesDocument, when you write
DocOne.FieldGetText
this returns the value of the field FieldGetText as an array. Since you probably have no such field, the value returned is an array containing one string whose value is “”. Then you try to reference the array with the index “docdate”. But since “docdate” is not a number, it can’t be used as an array reference. Hence the type mismatch.
You might instead try:
Set DocCreateddate = DocOne.GetItemValueDateTimeArray(“docdate”)(0)
or
Set DocCreateddate = DocOne.GetFirstItem(“docdate”).DateTimeValue
or even
Set DocCreateddate = New NotesDateTime(DocOne…docdate(0))
though that is a little sloppy since you’re converting the value to a LotusScript date/time variant, then into text, then into a NotesDateTime object, when it was already available as a NotesDateTime.
Note: I’m assuming here that docdate is in fact a date/time field, not text. Don’t make me come over there.
Subject: RE: TimeDifference Question
Well, I gave it another attempt. I don’t believe the code is working correctly. It’s not collecting the right documents.
I want to get documents that are 5 days old from today’s date. Any suggestions on what I’m doing wrong?
Dim Todaydate As NotesDateTime
Dim DocCreateddate As NotesDateTime
Dim Howold As Integer
Set DocOne = collectionone.GetFirstDocument
If Not DocOne Is Nothing Then
Set Todaydate = New NotesDateTime (“Today”)
Set DocCreateddate = DocOne.GetFirstItem(“docdate”).DateTimeValue
Howold = Todaydate.TimeDifference(DocCreateddate)/86400
If Howold < 6 Then
Set NewDoc = DB.CreateDocument
…
… do more stuff
…
Do Until DocOne Is Nothing
Subject: RE: TimeDifference Question
Well for one thing, you can use a datetime variant isntead of the NotesDateTime object and further simplify your code.
Dim varToday as Variant
varToday = Today
Set DocOne = collectionone.GetFirstDocument
If Not DocOne Is Nothing Then
Do While Not DocOne Is Nothing
Howold = Fix(varToday - DocOne.GetFirstItem(“docdate”)(0)) 'I hope you store your dates as dates!!!
If Howold > 5 Then
Set NewDoc = DB.CreateDocument
'… do more stuff
Set DocOne = collectionone.GetNextDocument(DocOne)
End If
Loop
ENd If
hcl-bot
November 9, 2007, 8:29am
10
Subject: RE: TimeDifference Question
Thanks for the response!
The docdate is a date/time field.
I think I’ll try the GetItemValue.
Thanks again!!!
hcl-bot
November 8, 2007, 9:52pm
11
Subject: RE: TimeDifference Question
Then Stephen’s response is your answer - use GetItemValue instead of FieldGetText - and use (0) subscript.