The standard datepicker for "Date of Birth" field in Contact has a limited range of years available.It is unsuitable for capturing a contact's date of birth. I have used apex:input but how can I save the value provided by the user in the Date of Birth field in Contact?

Visualforce page:

<apex:page standardController="Contact" docType="html-5.0" extensions="DatePicker">
 <apex:pageMessages />
  <apex:sectionHeader title="Custom Date Picker" subtitle="Create Contact" />
  <apex:form id="frm">  
    <apex:pageblock title="Opportunity" id="pb">
      <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!save}" />
        <apex:commandButton value="Cancel" action="{!Cancel}" />
      <apex:pageBlockSection id="pbs">
        <apex:inputField value="{!Contact.Salutation}" />
        <apex:inputField value="{!Contact.FirstName}" />
        <apex:inputField value="{!Contact.LastName}" />
         <apex:pageBlockSectionItem >
         <apex:outputLabel value="Date of Birth" for="birthdate" />
         <apex:input type="date" value="{!dat}"/>



Apex Class:

public class DatePicker 

    public DatePicker(ApexPages.StandardController controller) {


    public String datename {get; set;}
     public Date dat {get;set;}
    public DatePicker() {


I have checked https://developer.salesforce.com/forums?id=906F00000008kzBIAQ but this doesn't seem to work.

2 Answers 2


Here is code taking the same approach as your link of modifying the date pickers that Visualforce generates. This will only work if Salesforce continue to leave the specific HTML they generate unchanged in this area.

Working example page:

<apex:page standardController="Contact">
                <apex:inputField value="{!Contact.Birthdate}"/>

<script src="https://code.jquery.com/jquery-1.12.4.min.js"/>
(function($) {
    function addYearsToDatePickers() {
        var currentYear = $('select#calYearPicker > option:first-child').val();
        for (var year = currentYear - 1; year > 1900; year--) {
            $('<option value="' + year + '">' + year + '</option>').prependTo('select#calYearPicker');


When adding JavaScript, always check in your browser's JavaScript console for errors.


I want contact Birthdate of apex class code.when iam click birthdate the date will be showcase to me like calender.

Regards Raviteja

You must log in to answer this question.

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