K2 blackpearl: Create DateTime[] from data fields

1.1k Views Asked by At

I cannot figure out how to use the DateTime Maximum function with multiple data fields. I have 2 (DateTime) data fields that I want to get the maximum value.

The "values" field only lets you type a literal or drop in ONE field. How can I create an array of my 2 fields?

Thank you!

enter image description here

1

There are 1 best solutions below

0
On BEST ANSWER

Ob

I think the problem you are having is that the input is not a date but an array of dates: DateTime[]

I don´t think this function is typically made to help you find the biggest between 2 dates in 2 datafields.

The way this function works is that you need to give it an array and of course the second param is a date.

To do so, you can use a smartobject that will return you a list of datetime (when you call the list, make sure you don´t return just the first, this is the default value).

The function will then work fine and tell you which of the dates in this list is the 'maximum'.

Now, if you really have to use the dates in those datafields, you will first need to convert those 2 datetime into an array of datetime. Unfortunately, I am not aware of a function able to do that (I may be wrong...).

I see 3 options nonetheless:

  1. You write a custom function that will do just that: take 2 input and return an array of them (there are Knowledge Base article explaining how to do that)
  2. You use a stored procedure (that you call thru a smart object) that converts your 2 data into an array and you then can use the function you mentioned 3 . I think you may simplify even further by letting the stored procedure find the max for you. See below.

A simple version for #3 would be:

declare @D1 datetime

declare @D2 datetime
SET @D1 = getdate()
SET @D2 = getdate()+100

if (@D1>@D2)
    select @D1
else
    select @D2

I hope this helps.