Notes Ninjas Notes Ninjas
Lotus Notes hints, tips, error messages
NotesDateTime help sheet

Hint Short Cut: Add this to your code & documentation to help you find this page.
http://www.notesninjas.com/#NotesDateTime or http://www.notesninjas.com/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 )

 

For time and date picking solutions please check out notes templates.

 

 


 Jump to:     Notes Tips
    Lotus Notes Index 
  Register for Tips
Previous Lotus Notes Tip 
    Next Lotus Notes Tip
Your company logo here?
Adam Foster
Free Cash Making Web Site
Free Revenue Earning Blog Site
 Free Revenue Earning Newsletter Site   
Free Search Pages Free Web stats
Free Contact Us page
Cheap .com domain names
 Need a website or 
   Lotus Notes
  problem solved?
Adam Foster
Lotus Notes and Domino 6 Programming Bible by Brian Benz, Rocky Oliver
Covers all the programming techniques, concepts, and languages used with Notes and Domino, as well as the many new features of Domino 6 Thoroughly examines the Notes and Domino role with Java, XML, Web services, and other IBM products and technologies Provides extensive code and examples, many geared to the needs of administrators High-profile authors, known to their audience through conferences and articles Companion Web site shows example applications from the book running on a live Domino server and provides code download.
See at: Amazon.co.uk | Amazon.com |