couch
unread,Nov 28, 2009, 12:40:27 AM11/28/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to XMPie Interest Group
In the Plan Objects area, right click on functions and select:
New Function -> VBScript -> Date
Name the new function AddDate
Right click on the new AddDate function and Add the following three
parameters:
startDate (type=Date)
num (type=number)
datePart (type=string)
Now double click on the AddDate function, in in the top area, under
where it says Function AddDate(startDate, num, datePart) add the
following code:
<cut below this line>
' This function is to replicate the VB dateAdd() inside of uPlan.
'
' requires three attributes: startMonth, num, datePart - similar to
the VB function.
' startDate is the date to apply the calculation to, num is the
integer to add, valid entries for datePart are:
' yyyy - Year
' q - Quarter
' m - Month
' y - Day of year
' d - Day
' w - Weekday
' ww - Week of year
' h - Hour
' n - Minute
' s - Second
startDate = startDate
num = num
datePart = datePart
AddDate = dateAdd(datePart, num, startDate)
<end cut above this line>
You can see the actual function is just a few lines. The lines
starting with ' are comments to show you what you can enter for the
datePart...
Now how you use it:
In the ADOR object or variable where you want to do the date math;
simply drag up to the expression window your new function, and replace
the parameter names with the required values.
EG:
AddDate(|->[DatabaseDate],90,"d") <- will add 90 days to the
DatabaseDate
AddDate(|->[DatabaseDate],-1,"m") <- will remove one month from the
DatabaseDate
Of course, you can also use it with XMPie's date formatting functions,
eg:
FormatDate(AddDate(|->[DatabaseDate],90,"d"),"dddd, MMMM dd, yyyy")