Using TimeDifference with 12h and 24h format

Hello,

I read all the topics but didn’t find any answer to my question. Here it is :

I have an agent which run every hour. It has to compare current time with a time field on a document and process the document if necessary. The issue is : my local desktop is French and the hour format is 24h. But the server is an English one, and is in 12h format. Will TimeDifference method will know how to compare both?

Here is a part of my code :

'Now will process only if current time is bigger than server time

		Set serverTime = New NotesDateTime(docServer.GetItemValue("fl_time")(0)) 'server time

		If currentDate.TimeDifference(serverTime)>=0 Then

But if it’s 12h01 AM and my time field is 8h20, it will run it but it’s not supposed to… because it’s really 00h01… How can I manage that? Thanks a lot, I hope I explained well my problem, if not tell me…

Subject: Using TimeDifference with 12h and 24h format

there is a special NotesDateTime Class for handling such situations, it has good examples too.

See the help in NotesItem and NotesDateTime, you will find the solution there.

Gettting DateTime the way you are doing will lead to a number of problems, as it never gets converted properly.

Subject: RE: Using TimeDifference with 12h and 24h format

Ok I followed your advises and it’s working fine now, thank a lot!!!

Subject: RE: Using TimeDifference with 12h and 24h format

The problem you describe, I’m not sure whether it’s what’s actually happening, or whether you are just afraid it might happen.

Is fl_time a date/time value, or is it text? If it’s text, you’re in trouble. Never, ever, ever, store a date/time value as text, because different systems (and users in different countries) will interpret that text differently. Without knowing the settings of the system that stored the value, it is impossible to tell what time was intended.

If you store a date/time value properly, as a date/time field, it’s stored as numbers of seconds since a fixed reference date/time. This is independent of how it’s converted to text for display. All computers can agree on what time it represents, even though they would display the time differently.

It’s just like number fields. If you store a string, “7,000” means 7 to some systems and 7000 to others. But if you use a number field, it’s the same number to everyone and you can do math without caring whether the computer uses “.” or “,” as a decimal separator.

The NotesDateTime class operates on date/time values in this way. It doesn’t need to know how the date is formatted for display, to do math on it. But you must give it good input. If you pass the constructor a text string that was generated by another computer, it will try to interpret that string using the settings of the current computer.

N.B. that just because a field is defined as date/time on a form, doesn’t mean that a date/time value is necessarily stored in documents. It depends how the field gets assigned, whether thru code or what. Use the document properties from a view to check the real datatype of the item.