Manage Learn to apply best practices and optimize your operations.

Get Server Time Function

I recently had a request to always use the server time/date when setting values
on a form. With the exception of Modified and Created, all the date/time
functions use the workstation clock. I solved this problem by creating a
document in script and getting the Created date. Then I figured out the
difference between the Created date and the workstation time in seconds. I
then created a function called get server time that uses a parameter to tell
what format to return the time in and returns the server time in that format.
Globals Declarations
Dim dblTimeDiff As Double

Globals Initialize
dblTimeDiff = SetTimeDiff

Function SetTimeDiff As Double
%REM
This function is here because there was a requirement to get/set dates on the
document using the server clock instead of the local workstation.
The created property returns the date a document was created. That date comes
from the server. This Function determines the difference in seconds between
the server clock and the workstation
%END REM
Dim session As New NotesSession

Dim doc As New NotesDocument(Session.CurrentDatabase)

Dim datetimeWorkStation As New NotesDateTime(Now)
Dim datetimeServer As NotesDateTime

Set dateTimeServer = New NotesDateTime( doc.Created )

SetTimeDiff = datetimeServer.TimeDifference(datetimeWorkStation)
End Function

Function GetServerTime(strFormat As String) As String
%REM
This function is here because there was a requirement to get/set dates on the
document using the server clock instead of the local workstation.
The created property returns the date a document was created. That date comes
from the server. After finding the number of seconds difference between
the server and the Now function you then have a value to adjust future calls to
the Now function. The variable dblTimeDiff is a global set by the function
SetTimeDiff
%END REM
Dim datetimeWorkStation As New NotesDateTime(Now)
Call datetimeWorkStation.AdjustSecond( dblTimeDiff )

Select Case strFormat
Case "Date"
GetServerTime =
Format$(Left$(datetimeWorkStation.LocalTime,20),"mm/dd/yyyy")
Case "Time"
GetServerTime =
Format$(Left$(datetimeWorkStation.LocalTime,20),"hh:nn AM/PM")
Case "DateTime"
GetServerTime =
Format$(Left$(datetimeWorkStation.LocalTime,20),"mm/dd/yyyy hh:nn AM/PM")
Case "Year"
GetServerTime =
Format$(Left$(datetimeWorkStation.LocalTime,20),"yyyy")
Case Else
Msgbox "Invalid Parameter",0+16,"Get Server Time"
End Select
End Function

Now you can just use Calls to GetTime instead of using the Now function.

Dig Deeper on Domino Resources - Part 5

SearchWindowsServer
Search400
  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

SearchDataCenter
SearchContentManagement
Close