dateParm

5 posts / 0 new
Last post
mpine@clearbala...
Offline
Joined: 08/22/2018 - 16:11
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's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

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@clearbala...
Offline
Joined: 08/22/2018 - 16:11

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

Images: 
Brian Element's picture
Brian Element
Offline
Joined: 07/11/2012 - 19:57

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.

mpine@clearbala...
Offline
Joined: 08/22/2018 - 16:11

Thank you.  That helped.