Calculate date and time differences - Save date and time in IR

Version 1

    Intelligent Reporting uses all type of VB functions. In CDS v2.3 with the new expression editor and the intellisense, these function are easier to find and use.


    Few functions to use to calculate the difference between date and time:



    DateDiff: MSDN article - DateAndTime.DateDiff Method (DateInterval, DateTime, DateTime, FirstDayOfWeek, FirstWeekOfYear) (Microsoft.VisualBasic)

    DateDiff( interval ,date 1, date 2) as double

    Use in Intelligent Reporting: =DateDiff("s","01-Jan-00 00:00:00","01-Jan-00 00:01:00")

    This expression will return: 60  (60 seconds)


    DateAdd: MSDN article - DateAdd Function

    DateDiff( interval , number , date) as date

    Use in Intelligent Reporting: =DateAdd("s",60,"01-Jan-00 00:01:00")

    This expression will return: 01-Jan-00 00:02:00



    These two functions can be easily use with all intelligent reporting fields such as: Injection_AcquiredDate, Injection_DAMethodLatestFileChange, ...

    One application would be to be able to save in a variable (expecting a double) a date that would be used in other reporting item.


    1st step. Save the date in a variable.

    Variable :=DateDiff("s",Now,Injection_AcquiredDate)

    Which save the difference in seconds between the injection date and time and the time now (arbitrary date and time).


    2nd step. Return the date and time:

    =String.Format("{0:yyyy-MM-dd HH:mm:sszzz}",DateAdd("s", test, Now))

    Where string.format formats the date and time to a ISO format

    And DateAdd, retrieve the initial date saved in the variable.



    PS: these functions or approach can be used in Custom Calculator as well.