Help with NotesDateTime

Hi There,

I am trying to mark some documents as current if they are in between the dates on the configuration documents. I am getting a type mismatch, can anyone help ?

Code :

Sub Initialize

Dim s As New NotesSession

Dim db As notesDatabase

Dim CDoc As NotesDocument

Dim doc As NotesDocument

Dim DT As NotesDateTime

Dim StartDT As NotesDateTime

Dim EndDT As NotesDateTime

Dim v As NotesView

Dim strPath As String

Dim DocColl As NotesDocumentCollection



Set db = s.CurrentDatabase

Set v = db.GetView("ImageLkp")

Set CollV = db.GetView("ImgLkps")



'Set today

Set DT = New NotesDateTime("Today")

Set CDoc = v.GetDocumentByKey("Yes")  ' Get the current image path

Set DocColl = CollV.GetAllDocumentsByKey("Index")

Set doc = DocColl.GetFirstDocument



Do Until doc Is Nothing

	Set StartDT = New NotesDateTime(Cdat(doc.DT_From(0)))

	Set EndDT = New NotesDateTime(Cdat(doc.DT_To(0)))

	If DT > StartDT And DT < EndDT Then

		doc.Used = "Yes"

		CDoc.Used = ""

		Call doc.Save(True,True)

		Call CDoc.Save(True,True)

		Exit Sub

	End If

	Set doc = DocColl.GetNextDocument(doc)

Loop

End Sub

Getting the error on the IF DT > StartDT line.

Thanks for any help

F1H

Subject: Help with NotesDateTime

You cannot compare Objects using relation operators > or < or…

You are basically saying:

If apple > orange Then

Instead, you should use the LSLocalTime property of the NotesDateTime class because that is a numeric value.

Subject: RE: Help with NotesDateTime

Thanks for that!, Feel a bit lost when it comes to NotesDateTime. How is this :

Sub Initialize

Dim s As New NotesSession

Dim db As notesDatabase

Dim CDoc As NotesDocument

Dim doc As NotesDocument

Dim DT As NotesDateTime

Dim StartDT As NotesDateTime

Dim EndDT As NotesDateTime

Dim v As NotesView

Dim strPath As String

Dim DocColl As NotesDocumentCollection



Set db = s.CurrentDatabase

Set v = db.GetView("ImageLkp")

Set CollV = db.GetView("ImgLkps")



'Set today

Set DT = New NotesDateTime("Today")

Set CDoc = v.GetDocumentByKey("Yes")  ' Get the current image path

Set DocColl = CollV.GetAllDocumentsByKey("Index")

Set doc = DocColl.GetFirstDocument





Do Until doc Is Nothing

	Set StartDT = New NotesDateTime(Cdat(doc.DT_From(0)))

	Set EndDT = New NotesDateTime(Cdat(doc.DT_To(0)))

	If DT.LSLocalTime > StartDT.LSLocalTime And DT.LSLocalTime < EndDT.LSLocalTime Then

		doc.Used = "Yes"

		CDoc.Used = ""

		Call doc.Save(True,True)

		Call CDoc.Save(True,True)

		Exit Sub

	End If

	Set doc = DocColl.GetNextDocument(doc)

Loop

End Sub

Thanks

F1H

Subject: RE: Help with NotesDateTime

Problem…

In this line:

If DT.LSLocalTime > StartDT.DateOnly And DT.LSLocalTime < EndDT.DateOnly Then

you are now comparing a number to a string. Why not use LSLocalTime on both NotesDateTime objects? Also, if you really need to use only the date portion (while ignoring the time portion), you can do:

vStartDate = StartDT.LSLocalTime

vStartDate = DateSerial(Year(vStartDate), Month(vStartDate), Day(vStartDate))

(and similarly for EndDT)

then use

If DT.LSLocalTime > vStartDate And DT.LSLocalTime < vEndDate.DateOnly Then

Any possibility of the times being i different timezones?

Subject: RE: Help with NotesDateTime

Not at all…

i am having a problem of trying to get the value from the document to the DateTime variable…Type mismatch

Any ideas with that? I will apply your idea also.

Thanks

F1H

Subject: RE: Help with NotesDateTime

Hi,

i am now getting a Type Mismatch in runtime on the line :

Set StartDT = New NotesDateTime(Cdat(doc.DT_From(0)))

Anyone got any ideas?

Thanks

Jamie

Subject: RE: Help with NotesDateTime

Look at designer help - the constructor for a NotesDateTime object expects a string and you are passing it a datetime variant. If the field is already a string, no reason to use CDat.

Or…

Set StartDT = New NotesDateTime(“”)

StartDT.LSLocalTime = Cdat(doc.DT_From(0))

LSLocalTime is read/write property

Subject: RE: Help with NotesDateTime

If I might throw in my two cents…

Why do a comparison of LSLocalTime when he has three NotesDateTime objects instantiated. I’d use the TimeDifference method instead:

If curDT.TimeDifference(startDT) > 0 and curDT.TimeDifference(endDT) < 0 then…

you know that it falls within the range.

Just the way I would handle it…

brandt

Subject: RE: Help with NotesDateTime

Good point, Brandt.

One can even take it a step further and ask why there’s a need to instantiate several NotesDateTime objects at all and just work directly with LS datetime variants.

Subject: RE: Help with NotesDateTime

Thanks for the help so far, but i am still getting a Type mismatch when i am trying to pass in the value from the notesdocument…i must be missing something here!

Sub Initialize

Dim s As New NotesSession

Dim db As notesDatabase

Dim CDoc As NotesDocument

Dim doc As NotesDocument

Dim DT As NotesDateTime

Dim DocSDate As NotesItem

Dim StartDT As NotesDateTime

Dim EndDT As NotesDateTime

Dim v As NotesView

Dim strPath As String

Dim DocColl As NotesDocumentCollection



Set db = s.CurrentDatabase

Set v = db.GetView("ImageLkp")

Set CollV = db.GetView("ImgLkps")



'Set today

Set DT = New NotesDateTime("Today")

Set CDoc = v.GetDocumentByKey("Yes")  ' Get the current image path

Set DocColl = CollV.GetAllDocumentsByKey("Index")

Set doc = DocColl.GetFirstDocument





Do Until doc Is Nothing

	Set StartDT = New NotesDateTime("")

	StartDT.LSLocalTime = Cdat(doc.DT_From(0))

	Set EndDT = New NotesDateTime("")

	EndDT.LSLocalTime = Cdat(doc.DT_To(0))

	If DT.TimeDifference(startDT) > 0 And DT.TimeDifference(endDT) < 0 Then

		doc.Used = "Yes"

		CDoc.Used = ""

		Call doc.Save(True,True)

		Call CDoc.Save(True,True)

		Exit Sub

	End If

	Set doc = DocColl.GetNextDocument(doc)

Loop

End Sub

I have tried the line with the CDat and without, neither work.

any help would be appreciated.

Thanks

F1H

Subject: RE: Help with NotesDateTime

Sub InitializeDim s As New NotesSession

Dim db As notesDatabase

Dim CDoc As NotesDocument

Dim doc As NotesDocument

'#############################

'Forget about NotesDateTime - your code doesn’t need the overhead and greater complexity

'Dim DT As NotesDateTime

'Dim DocSDate As NotesItem

'Dim StartDT As NotesDateTime

'Dim EndDT As NotesDateTime

Dim datToday as Variant

Dim datFrom as Variant

Dim datTo as Variant

'#############################

Dim v As NotesView

Dim strPath As String

Dim DocColl As NotesDocumentCollection

Set db = s.CurrentDatabase

Set v = db.GetView(“ImageLkp”)

Set CollV = db.GetView(“ImgLkps”)

'Set today

'#############################

'Forget about NotesDateTime - your code doesn’t need the overhead and greater complexity

'Set DT = New NotesDateTime(“Today”)

datToday = Today()

'#############################

Set CDoc = v.GetDocumentByKey(“Yes”) ’ Get the current image path — Are you sure you have a document here??? Your code doesn’t test for CDoc Is Nothing

Set DocColl = CollV.GetAllDocumentsByKey(“Index”)

Set doc = DocColl.GetFirstDocument

Do Until doc Is Nothing

'#############################

'Forget about NotesDateTime - your code doesn’t need the overhead and greater complexity

'Also - before you indiscriminately use DT_From and DT_To, how do you know they contain “date-like” values?

'Please don’t tell me they are strings that look like dates…

'Set StartDT = New NotesDateTime(“”)

'StartDT.LSLocalTime = Cdat(doc.DT_From(0))

'Set EndDT = New NotesDateTime(“”)

'EndDT.LSLocalTime = Cdat(doc.DT_To(0))

datFrom = Cdat(doc.DT_From(0))

datTo = Cdat(doc.DT_To(0))

'If DT.TimeDifference(startDT) > 0 And DT.TimeDifference(endDT) < 0 Then

'#############################

If (datFrom - datToday > 0) And (datTo - datToday < 0) Then

doc.Used = “Yes” 'Does changing this value in the document also change whether it appears in the view named “ImgLkps”

CDoc.Used = “”

Call doc.Save(True,True)

Call CDoc.Save(True,True)

Exit Sub

End If

Set doc = DocColl.GetNextDocument(doc)

Loop

End Sub

Subject: RE: Help with NotesDateTime

Wow - Thanks very much!!

that is working great now, didn;t expect to get the whole code!

thanks very much for your help.

F1H