I'm having trouble passing a JavaScript date type var as the apex param value. The following is a sample code segment...

    var today = new Date(93740000);

    <apex:outputText value="{0,date,yyyy',' M',' d}">
        <apex:param value="today" />

This gives me the error:

Error: The value attribute on is not in a valid format. It must be a positive number, and of type Number, Date, Time, or Choice.

How can I resolve this issue and use the JavaScript date in Visualforce code?

1 Answer 1


JavaScript is client side, while apex code renders server side. In other words, Salesforce tries to convert the literal value of "today" into a date using valueOf, which fails, because it's not a valid formatted date.

You have a few choices here, depending on the exact usage you're going for. Perhaps the easiest would be to store the value in a hidden field:

<apex:inputHidden id="DateVal" value="{!myDateField}" />

You can reference this in Apex Code, and it'll be available in the controller on the next round trip (e.g. by using an action function). There must be a public getter and setter that matches the value in the input field for this to work. I'd recommend using a number type if you plan on using Epoch Time (number of milliseconds since 1970).

Other variations to this technique exist, but you'll need a server side variable to get Visualforce to read your date value

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .