About 6 days ago Sandeep published some VBScript code for date difference
calculations. Do a search on "calculate hours worked from two date/time
cells" in this newsgroup for the code. You may have to modify it to suit your
needs, but it should get you started.
As for the second part of your question: If you opened the Scripting Editor
the first time for your form and you had JScript set as the scripting
language to use in InfoPath, you won't be able to switch to VBScript for that
form anymore by just setting the option through Tools > Options > Design tab
> language. Create a new form, set the language to VBScript, and THEN open
the Scripting Editor to be able to use VBScript in your InfoPath form.
---
S.Y.M. Wong-A-Ton
> Hello,
>
[quoted text clipped - 37 lines]
>
> Robert
Robert Grund - 12 Feb 2006 16:50 GMT
Thanks!!
That is what I was missing!! I have generated the form while it was still
set to JScript and have opened the Scripting Editor.
That was an information which I was seeking then whole time. The MS Office
Info Publisher 2003 book did not state that.
Robert
> About 6 days ago Sandeep published some VBScript code for date difference
> calculations. Do a search on "calculate hours worked from two date/time
[quoted text clipped - 59 lines]
>>
>> Robert
Robert Grund - 14 Feb 2006 16:23 GMT
Still have problems, with Datediff.
The two date fields are currently set as strings and the datediff calculates
the delta nicely. As I need date and time and when I change the field
format to that format, The script crashes!! Also the one field which will
be populated later on shows NaN. Is this normal? Why is it that Datediff
works with string format but not with Date-Time Format? Any suggestions what
I can still do?
I know, I could move to jscript but it will take to long learning a new
language, especially for what I want to do.
Robert
> About 6 days ago Sandeep published some VBScript code for date difference
> calculations. Do a search on "calculate hours worked from two date/time
[quoted text clipped - 59 lines]
>>
>> Robert
S.Y.M. Wong-A-Ton - 14 Feb 2006 18:50 GMT
What is the data type of the date fields? Are you using text boxes or date
pickers?
I think you might be confusing the data type with the format (Format button
on the Properties dialog box). Formatting only affects the way a date is
shown.
Did you read my other post where I said that InfoPath date data type has the
format YYYY-MM-DDThh:mm:ss in the background? This might be causing the
problem. Correct me if I'm wrong, but doesn't the DateDiff function accept
Date objects? Perhaps InfoPath's date format cannot be implicitly converted
to a Date object, in which case you will have to parse the date value
returned by InfoPath and explicitly construct a Date object to pass to the
DateDiff function.
NaN is normal if the result of the calculation wasn't a number, which is
true in this case because your calculation failed.
My suggestion would be to add some debugging code to your code. Add MsgBox
statements to print out the values of the date fields. Then use this
information to create valid Date objects in VBScript and pass them to the
DateDiff function. Try it, and if you are experiencing challenges, let me
know; I'll help you where I can.
And there is no need to learn JScript; VBScript should work too!
---
S.Y.M. Wong-A-Ton
> Still have problems, with Datediff.
>
[quoted text clipped - 73 lines]
> >>
> >> Robert