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..


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.

  • 1
    but in native salesforce picker format is MMDDYYYY but he wants it to be in the format YYYYMMDD.
    – Pankaj
    May 7 '13 at 6:19
  • 1
    Ok well maybe the following link will help :-) stackoverflow.com/questions/11834873/…
    – Jim
    May 8 '13 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 '13 at 20:09

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;  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.