1 Reply Latest reply on Jun 16, 2015 11:23 AM by jasong RSS
    lorenmc Explorer

    Using the Expression widget with date/time

    Hi, I'm trying to create two inputs to the query service of startDate and endDate.


    I want the endDate to default to the current date/time upon loading the mashup while the startDate being 3 months prior to the endDate.


    What's the proper way to do this? I have the Expression widget on my mashup but I'm not sure how to do this on the expression field.


    Thanks!



      • Re: Using the Expression widget with date/time
        jasong Creator

        I've done something similar, although usually I am using DateTime widgets as service inputs and use expressions to set the default selections. But this will work for direct service inputs as well.

         

        My suggestion is to have two expressions.

        Set them to have DateTime outputs.

        Expression1's expression would be: new Date()

        and Expression2's expression would be: new Date(new Date().getTime() - 7776000000)

         

        Then make sure to wire the outputs of Expression1 to the service's endDate and Expression2 to the service's startDate.

         

        You might consider making Expression2's formula more easily editable and dynamic. Create an input for the expression, make it a number, call it "months" and change the expression to:

        new Date(new Date().getTime() - (months*30*24*60*60*1000))

         

        A good tool to test javascript for your expressions is JSFiddle. Just wrap your code in an "alert()"