Tip

Storing date in date field irrespective of settings/time zone

Many Lotus Applications which are Client based need to use the Today's date or current date and store it in dd/mm/yyyy hh:mm:ss:tt AM/PM.

This tip helps you to perform the above action with the prerequisite that Time settings of the user should be in hh:mm:ss:tt format.


First get the server date and time in following format.

Set tempdoc = db.createDocument.
lt_ServerTime = tempdoc.Created.

 
timeformat = "hh:mm:ss AM/PM" 
If session.INTERNATIONAL.DateDMY
dateformat = "dd/mm/yyyy hh:mm:ss AM/PM"
elseif session.INTERNATIONAL.DateMDY then
dateformat = "mm/dd.yyyy hh:mm:ss AM/PM"
elseif session.INTERNATIONAL.DateYMD then
dateformat = "yyyy/mm/dd/ hh:mm:ss AM/PM" 
End If

lt_ServerTime = Format( lt_ServerTime , dateformat)

Dim dttime As New NotesDateTime( lt_ServerTime )

doc.dt_field1 = Cdat( dttime.LsLocaltime).

The value that gets stored in the field is in the Client m/cs date format and its value on Server will be in "dd/mm/yyyy".
To convert Time form one unknown zone to another Zone use following code.

Set dtTime = New NotesDateTime( lt_ServerTime)
Set ls_date1 = dttime.GMTtime
Set ls_date1 = StrRight( ls_date1 ," GMT").

ls_Hour = Cint(Strleft(ls_date1 ,":" , 5,1))
le_Sec = Cint(Strrightback( ls_date1 ,":" , 5,1))
ls_Minute = Strleft(Strright(ls_date1,":",5,1),":",5,1)


ls_Hour1 = Hour( dtTime.LocalTime)
ls_Minute1 = Minute( dtTime.LocalTime)
ls_Sec1 = Second( dtTime.LocalTime)

In_AdtHour = ls_Hour1 - ls_Hour + x( known difference between 1 zoneand GMT)
In_AdtMinute = ls_Minute1 - ls_Minute + y

In_AdtSec = ls_Sec1 - ls_Sec + z

Call dtTime.djusthour( In_AdtHour )
Call dtTime.AdjustMinute( In_AdtMinute )
Call dtTime.AdjustSecond( In_AdtSec )

doc.field1 = dtTime.TimeOnly.

This was first published in January 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.