2

I need Date picker field in visualforce page.

When select that field the date format should like YYYY-MM-DD

How to achieve this?

Thanks for all your response..

1

2 Answers 2

5

You can bind directly to a date field on an sObject(in my example contact) using Visualforce like this:

<apex:inputField value="{!Contact.BirthDate}" />

Visualforce will render as appropriate based on the data type of your field. So if your using standard Salesforce styles in your page, this will cause the salesforce default calendar to be displayed. Otherwise you can take a look here for some more ideas. Also it may be worthwhile to take a look at this for info on how you can format dates in VF.

3
  • 1
    but in native salesforce picker format is MMDDYYYY but he wants it to be in the format YYYYMMDD.
    – Pankaj
    May 7, 2013 at 6:19
  • 1
    Ok well maybe the following link will help :-) stackoverflow.com/questions/11834873/…
    – Jim
    May 8, 2013 at 4:10
  • Note that if the user doesn't have write access to the proxy object's field, it will render on the screen as a read-only value.
    – tomlogic
    Nov 20, 2013 at 20:09
0

Native salesforce picker format is MMDDYYYY. To change it into YYYYMMDD, use below JavaScript code example:

var EffDate=document.getElementById("effdate").value;
if (EffDate) { 
    EffDate = EffDate.replace(/(\d{4})-(\d{1,2})-(\d{1,2})/, function(match,y,m,d) { 
        return m + '/' + d + '/' + y;  
    });
}

You must log in to answer this question.

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