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

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

SearchWindowsServer

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchDataCenter

SearchContentManagement

Close