CA Client Automation

 View Only
  • 1.  Need to figure out how to do date math in CA

    Posted Jan 22, 2019 03:29 PM

    Working in: DM Scripting 14.0.1000.194

    It seems that I am missing some components of a Function that I am working in:

     

    The following code works for say like a few days ago, but does not seem to traverse a year.  For example, take NOW and subtract 105 days ago.

     

    '***************************************************************************************************
    'This function will add or subtract a number days from a provided date
    '***************************************************************************************************
    Function DayAdd(ByRef tmpDate as DateTime, DayModification as integer) as Boolean
    Dim i as integer
    Dim tDayModification as integer

    if DayModification < 0 then
    tDayModification = ((DayModification) * (-1))
    if tmpDate.Day < tDayModification then
    i = tmpDate.day - DayModification
    tmpDate.month = tmpDate.month - 1
    if tmpDate.month = 0 then
    tmpDate.year = tmpDate.year - 1
    tmpDate.month = 12
    tmpDate.day = 31 + i
    else
    tmpDate.day = GetDaysInMonth(tmpDate) + i
    end if
    else
    tmpDate.day = tmpDate.day + DayModification
    end if
    else
    if DayModification + tmpDate.day > GetDaysInMonth(tmpDate) then
    tmpDate.day = ((DayModification + tmpDate.day) - GetDaysInMonth(tmpDate))
    tmpDate.month = tmpDate.month + 1
    if tmpDate.month = 13 then
    tmpDate.month = 1
    tmpDate.year = tmpDate.year + 1
    end if
    else
    tmpDate.day = tmpDate.day + DayModification
    end if
    end if

    DayAdd = True

    End Function 'DateAdd

    Thanks.



  • 2.  Re: Need to figure out how to do date math in CA
    Best Answer

    Posted May 14, 2019 05:09 PM
      |   view attached

    HI, sorry I've been off the forums for a while due to email problems. Not sure if you still need this but I have the attached DMS functions to perform date math. There are several functions included to convert dates to the required formats so you can do math on them:

     

    • StringToDate:            Converts a string date in format MM/DD/YYYY to a SYSDATE structure for use in subsequent functions
    • DateToString:            Converts a SYSDATE function to MM/DD/YYYY string for output
    • GetDaysFromDate:   Converts a SYSDATE structure to an Integer which is # days since 03/01/0000. 
      • You can add or subtract days to/from this number then convert back to a SYSDATE then to a string
      • You can compare two such integers to calculate a difference between two dates
      • The reason the function calculates from 03/01/0000 not 01/01/0000 is because it allows for leap year calculations to be a linear function.
      • PLEASE do not ask me to describe how this works, I simply took an algorithm I found which was published by some folks way smarter than I am and coded it.
    • GetDateFromDays:   Converts number of days since 03/01/0000 back to a SYSDATE. Again please don't ask me to explain the algorithm, it was all I could do to convert the algorithm I found to code, made harder by the lack of a LONG INT in DSM scripts.

     

    Hope this helps!

    Steve

    Attachment(s)

    zip
    Date Functions.DMS.zip   1 KB 1 version