cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X

Using the Expression widget with date/time

lorenmc
1-Newbie

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!



1 REPLY 1
jasong
1-Newbie
(To:lorenmc)

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()"

Top Tags