Date Difference Calculation - InfoPath Dev
in

InfoPath Dev

Date Difference Calculation

Last post 01-11-2009 09:19 PM by Alec Pojidaev. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 12-15-2006 03:50 AM

    Date Difference Calculation

    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
  • 12-15-2006 04:22 AM In reply to

    Re: Date Difference Calculation

    Hi,
    Try this link
    http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=1870

    Hope this helps you!
    Shilpa
    INFOPATHDEV India
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.