Skip to main content

dateParm

Hi, 
I am attempting to create two "dateParm"s without having to actually type both in an input box.  DateParm will be an inputbox (example, i type in "20181127")
DateParm1 should always be 4 days prior to "dateParm" .  How can i create a custom formula to make DateParm1 = dateParm - 4 days. 
Sub Main
 IgnoreWarning(True)             Client.CloseAll              dateParm = InputBox ("Enter Date String (YYYYMMDD):  ")  dateParm1 = dateParm - 4 

Brian Element Wed, 11/28/2018 - 14:43

Hi there,

In IDEAScript there is an interesting trick, all the @ functions avialable in the Equation Editor are also available in IDEAScript by changing the @ for an i.  The only downside is it only works for @ functions available prior to IDEA V9 but fortunately that is most of them.  So for your question you can use the @DaysToD and @DtoDays to change the date to a number, subtract 4 days and then change it back to a date.  Here is some sample code for you:

Sub Main
Dim dateParm1 As String
Dim dateParm2 As String
dateParm1 = InputBox ("Enter Date String (YYYYMMDD): ")
dateParm2 = iDToDays(dateParm1) - 4
dateParm2 = iDaysToD(dateParm2 )
MsgBox "Entered date: " & dateParm1
MsgBox "Date 4 days earlier: " & dateParm2
End Sub

mpine@clearbal… Wed, 11/28/2018 - 16:17

In reply to by Brian Element

Thank you Brian.  This has helped.  However, I am still getting an error.  I was hoping the msg box would show "2018-11-23" 
 
 

Brian Element Wed, 11/28/2018 - 17:06

You need to make sure your date is in the YYYYMMDD format exactly.  Any other format will cause an error as this is the native IDEA format.  If it is different you need to change it to the YYYYMMDD format before actually using the function.

The website encountered an unexpected error. Try again later.