Finding earliest date

Viewing 4 reply threads
  • Author
    Posts
  • February 20, 2020 at 6:31 AM #39592

    Larry Stoter
    Participant

    Do functions like getMinOfField(date_id) work with date fields? I suspect not …

    I have a form with a number of records and a date field. The dates in the date field are not necessarily in order of entry. I want to find the earliest date in in the date field. The following script reurns O ….

    var date_id = 'fld-1482677011584a9da584a27e8835f5a4';
    var FirstDate = form.getMinOfField(date_id);
    Utils.alertWithMessage('FirstDate','First date is ' + FirstDate);

    Suggestions for finding the earliest date?

    February 20, 2020 at 10:40 AM #39595

    Sam Moffatt
    Participant

    If you’re working at the form level, you can create a search and set the search with a custom sort order and then use that search to retrieve the set of records. If your search has the date field set from earliest, then the first record will have your minimum date in it.

    February 20, 2020 at 12:50 PM #39602

    Brendan
    Keymaster

    Hi Larry,

    Sam’s suggestion is the right way to do it for now.

    I would like to change the getMinOfField() function to work with dates too. But it’s tricky as dates are stored as a dictionary of values in the database and not just as a numeric value.

    Thanks,

    Brendan

    February 25, 2020 at 3:38 AM #39648

    Larry Stoter
    Participant

    I actually want to find the earliest date in a field as a step in a more complex script.

    However, I have an apparently easy solution :-) Create a new calculation field Date#, simply put the Date field into the calculation and then set the Result Type to Number. The Date# field then shows numbers – not sure what numbers but the earliest date has the smallest number in the Date# field.

    Which seems to do what I want.

    February 25, 2020 at 9:48 PM #39653

    Brendan
    Keymaster

    In a Calculation field when you return a Date value, the result is in terms of the Unix Epoch date format. That is, the number of seconds that have elapsed since January 1, 1970 00:00:00. So ya, I guess that’s a way to do it.

Viewing 4 reply threads

You must be logged in to reply to this topic.