< Back

Document Subject: NotesDateTime help sheet
Hint Short Cut: Add this to your code & documentation to help you find this page.
http://#NotesDateTime or http://A555F9/nn.nsf/ByAlias/NotesDateTime
Here are some helpful hints on using NotesDateTime, calendar views, converting between date fields and notesdatetime values, durations etc

If you have a time and a date field, you can convert that to a notes date time by doing this:

Dim niTime as notesitem

Dim TimeRequired as new notesdatetime("")

Set niTime = doc.getfirstitem("Time") 
Set TimeRequired = New NotesDateTime(niTime.text)
 
set niDate as notesitem

Dim DateRequired as new notesdatetime("")

Set niDate = doc.getfirstitem("Date
Set DateRequired = New NotesDateTime(niDate.text & " " & niTime.text)

 

If you have a time field and you wish to make it work with any date try this:

Set TimeRequired = New notesdatetime ( niTime.text )
Time.setanydate

 

Time difference and timedoubledifference (notes 5 only) can be read as "minus".

Remember that later dates are bigger than earlier dates.

eg

if clashend.timedifferencedouble(gapstarttime)<=0 Then
     msgbox "clash ends before we need to start so ok"

elseif  clashstart.timedifferencedouble(gapenddateAndtime)>=0 Then
     msgbox "Clash starts after our start time so ok"

else

msgbox "Could be a clash"

end if

 

Replacing a notes time with a notesdatetime value:

Set ni = doc.replaceitemvalue("start",ndtStart.lslocaltime)

 

To replace a time only value you need to have set .setanydate on the ndt first.

Set ndtTime = New notesdatetime ( niTime.text )
ndtTime.setanydate

Set ni = doc.replaceitemvalue("time",ndtTime.lslocaltime)

Note: This looks different in the notes document but there is no other way.

A time only field created by a form is type: "Time/Date List or Range" and is "16:15:00"

Created by lotusscript it is type: "Time/Date" and is "30/12/1899 16:15:00 GMT"

 

The second field used in calendar field is type number and shows the range of a booking.

The duration field is in minutes not seconds so should be divided by 60:

bookdoc.duration=(ndtgapend.timedifference( ndtgapstart) )/60

You must make sure the busy rows are a different colour in the view/folder properties.

I find the 2 day view is most effective for showing busy times.

 

If you want to update a text field with today's date and or time try this:

dim ndt as new notesdatetime("")

call ndt.setnow()

call doc.replaceitemvalue("Last_Updated", ndt.dateonly)

call doc.replaceitemvalue("Last_Updated", ndt.timeonly)

call doc.replaceitemvalue("Last_Updated", ndt.zonetime)

 

Convert NotesDocument & Notesitem properties to Notesdatetime values: lastmodified  created lastaccessed

dim lmndt as notesdatetime

Set lmndt = New notesdatetime("")

lmndt.LSLocalTime = doc.LastModified

If lastrun.TimeDifferenceDouble(lmndt)<0 Then needToUpdate=True

 

Add a notesdatetime field to a document that does not have time data

eg 12/02/2010 instead of 12/02/2010 00:00:00

Dim loopdatetime As NotesDateTime

Dim workdatetime As notesdatetime

Set workdatetime = New NotesDateTime(loopdatetime.DateOnly)
Call workdatetime.setanytime
Call  tdoc.replaceitemvalue("Workdate",workdatetime )

Get nice format of todays date

Dim mnthlist As String

Dim mnthlistarr As Variant

mnthlist="Dec~Jan~Feb~Mar~Apr~May~Jun~Jul~Aug~Sep~Oct~Nov~Dec"

mnthlistarr = Split(mnthlist,"~")

Dim todaydate As String

Dim ndtnow As New notesdatetime(Now)

todaydate=Right$("0" & Day(ndtnow.lslocaltime),2) & " " 

todaydate=todaydate & mnthlistarr( Month(ndtnow.lslocaltime)) 

todaydate=todaydate  & " " & Year(ndtnow.lslocaltime) 

gives "01 Jan 2015"

or for @function
monthlist="jan":"feb":"mar":"apr":"may":"jun":"jul":"aug":"sep":"oct":"nov":"dec";

TodaysDate:=@Today;


@Implode(

@Right("0"+@Text(@Day(TodaysDate));2):

@ProperCase(monthlist[@Month(TodaysDate)]):

@Text(@Year(TodaysDate))

;" ")


To get a sortable date 
"20151231"

@Text(@Year(@Modified))+@Right("0"+@Text(@Month(@Modified));2)+@Right("0"+@Text(@Day(@Modified));2);


Lotusscript Lastmodified not the same as @modified

Lastmodified will show the added date, where as @modified will show the last saved time.

Dim mnthlist As String

Dim mnthlistarr As Variant

mnthlist="Dec~Jan~Feb~Mar~Apr~May~Jun~Jul~Aug~Sep~Oct~Nov~Dec"

mnthlistarr = Split(mnthlist,"~")

Dim lmdate As String

Dim lmod As Variant

lmod=Evaluate("@modified",docRequest)

Dim ndtnow As New notesdatetime(lmod(0))

'this gives added date not modified

'Dim ndtnow As New notesdatetime(docRequest.lastmodified)

lmdate=Right$("0" & Day(ndtnow.lslocaltime),2) & " " 

lmdate=lmdate & mnthlistarr( Month(ndtnow.lslocaltime)) 

lmdate=lmdate  & " " & Year(ndtnow.lslocaltime)