Search code examples
vbscripthp-uft

HP UFT - how to get date range from two input dates


I am trying to get the date range from two input dates eg: "01.10.2016" and "05.10.2016" (its a date format in SAP)

I thinking date format is wrong, if it is wrong could anyone help me to how to convert this format as acceptable.

Also i'm trying to get all the date between two dates including limits and using it for automation. if any one know how to get all the dates help me in this.


Solution

  • DD.MM.YYYY is the date format used in Germany, where SAP have their headquarters. If you're using the right locale you should be able to convert the date string to a date directly via CDate.

    s = "01.10.2016"
    d = CDate(s)
    

    If that doesn't work for you (because your regional settings differ) you can for instance split the string at dots and build a date from the fragments via DateSerial:

    s = "01.10.2016"
    a = Split(s, ".")
    d = DateSerial(a(2), a(1), a(0))
    

    Once you converted the strings to date values you can calculate the difference between the two dates by subtracting one from the other

    delta = d2 - d1
    

    or by using the DateDiff function:

    delta = DateDiff("d", d1, d2)
    

    The individual dates d1 through d2 can be calculated for instance like this:

    For i=0 To DateDiff("d", d1, d2)
      WScript.Echo d1+i
    Next