Store as Date Only - using Script - A solution

In common with a few other people I have the need to store some dates as date only with no time set. The fields are defined as Date, the display date is ticked but not display Time. If I did this in Formula then @Date would be ideal, however I’m in LotusScript and by default I get a time portion of 00:00.

Why don’t I want the time portion - because the data is being shared with Business Objects and apparently the query can’t cope with them!

After a bit of faffing around, trying various NotesDateTime methods … and searching in this forum I had a brainwave. The field values are set using a button that runs Script, the fields are defined as computed and with a value of themselves.

The solution (& it seems to work, can’t say more than that) is to make the field formula @date(fieldname), then when you save you only get the date portion saved.

I hope this helps someone else avoid this issue.

Sue

Keywords: @Date LotusScript DateOnly

Subject: Store as Date Only - using Script - A solution

That is precisely what the NotesDateTime method SetAnyTime is designed to do.

Subject: RE: Store as Date Only - using Script - A solution

Here’s a routine I’ve been using for years:

Sub SetDateOnlyField ( doc As NotesDocument, fieldname As String, dateval As Variant )

'If input value is a date, save as a date-only Notes field.

'Default in LS creates a date-time value with a midnight time component.

If doc Is Nothing Then Exit Sub

If fieldname = "" Then Exit Sub



'If the input value is not a date (most likely blank), just use it as is

If Not Isdate( dateval ) Then

	Call doc.ReplaceItemValue( fieldname, dateval )

Else

	Dim ndt As New NotesDateTime( Format( Cdat(dateval) , "mm/dd/yyyy" ) )

	Call ndt.SetAnyTime

	Call doc.ReplaceItemValue( fieldname, ndt )

End If

End Sub