Hi Guys,
I hope you can help this time!! I have a problem using VBScript, I can use VB6 fine, but I have never used VBScript!
I am trying to find the difference between two dates, one date is in a text box and the other is the system date...
The following code is a snippet of how I am trying to understand how to do it, using two dates in two "Date Picker" controls and displaying the result in a text box...
Sub CalculateDateDifference()
Dim strStartDate
Dim strEndDate
Dim strDateInterval
Dim dtStart
Dim dtEnd
Dim intDateDiff
'Retrieve the ISO date from the InfoPath date fields
strStartDate = XDocument.DOM.selectSingleNode("/my:myFields/my:startDate").text
strEndDate = XDocument.DOM.selectSingleNode("/my:myFields/my:endDate").text
'Convert ISO date into VBScript date
dtStart = ISODateStringToVBDate(strStartDate)
dtEnd = ISODateStringToVBDate(strEndDate)
If Not IsNull(dtStart) And Not IsNull(dtEnd) Then
'Retrieve the date interval to be used
strDateInterval = XDocument.DOM.selectSingleNode("/my:myFields/my:dateInterval").text
Select Case LCase(strDateInterval)
Case "yyyy"
'Difference between dates in years
intDateDiff = DateDiff("yyyy", dtStart, dtEnd)
Case "m"
'Difference between dates in months
intDateDiff = DateDiff("m", dtStart, dtEnd)
Case "d"
'Difference between dates in days
intDateDiff = DateDiff("d", dtStart, dtEnd)
Case "h"
'Difference between dates in hours
intDateDiff = DateDiff("h", dtStart, dtEnd)
Case "n"
'Difference between dates in minutes
intDateDiff = DateDiff("n", dtStart, dtEnd)
Case "s"
'Difference between dates in seconds
intDateDiff = DateDiff("s", dtStart, dtEnd)
Case Else
'If interval is not recognized so use difference in days
intDateDiff = DateDiff("d", dtStart, dtEnd)
End Select
'Set the value of the dateDiff field
XDocument.DOM.selectSingleNode _
("/my:myFields/my:dateDiff").text = intDateDiff
End If
End Sub
I am getting an error on the line that is in red... please help!
Thanks for your help