How to set 'date only' or 'time only' values in fields through XPages

XPages always save date and time in a field

When a form has the fields with "date only" or "time only", then the stored data format are different between Notes Client and XPages.

For example, I prepared the field with "date only" named "Date" as following (sorry, screenshots are all Japanese) :

年月日のみをもつフィールド

And also field with "time only" named "Time":

時刻の表示のみをもつフィールド

Now I saved a new document with this form from Notes Client (9.0.1 FP3), then I got following fields' data.

Notesクライアントで日付フィールドを保存

Notesクライアントで日付フィールドを保存

As you see, "Date" field has "2015/03/02", and Time field has"14:35:00"

As the next, I created the simple XPage to save a new document with same form and fields so that I can compare the data between Notes Client and XPages.

XPagesで日付フィールドの保存

Below is the source code for Date field and Time field in XPages.

Date Field

Time Field

Each inputText specify date, time to the Type attribute of convertDateTime.

After saving a new document from this XPage, below is the screenshot of stored field data:

XPagesから保存された文書のDateフィールド

XPagesから保存された文書のTimeフィールド

So both of fields have "yyyy/MM/dd hh:mm:dd ZZ" format.

Why you need to save "date only" or "time only" data from XPages?

I just don't post this blog to argue which format is proper way and why XPages behaves differently.

In the real world, I think you or your customers already have the NSF apps and you may want to improve them as the web application by XPages. In that case, especially you decide to keep using the NSF from both Notes Client and XPages, then I recommend to adjust the field format to Notes Client one instead of XPages one so that all existing documents are supported both Notes Client and XPages without changing data.

Use setAnyTime()、setAnyDate() of NotesDateTime class

Maybe there are a lot of way to achieve what I want below. But one of easy way is using NotesDateTime class of SSJS.

The SSJS above converts the DateTime field format by using setAnyTime()、setAnyDate() in PostSaveDocument event after saving the XSP document .