+ Start a Discussion

Limit date Field

Hello, Is it possible to limit the data field to Month and Year only?I am trying to create a visual force page that has a to and from date.But would like to show only Month and Year to the User.


There is no way to actually have the system ignore the day part of a date field completely.  You could potentially have a workflow/trigger update it to always be the first of the month to apply some sort of convention.  You could also have a formula field/vf page display the date with different formatting (like mm/yyyy).  You could then also, make a custom text field or something and use a validation rule to enforce a mm/yyyy format.  I think some combo of those is going to be your best option.
Anup JadhavAnup Jadhav

Hi Michael,


you cannot format the date field directly, but you can create 2 seperate outputText tag with the date merge field as follows:


<outputText value="{!dateField.month}" /> <outputText value="{!dateField.year}" />


-A J


Alternatively, especially for output, you could just have the controller return a string...



//Controller public String getMonthYear() { return String.valueOf(myDate.month()) + '/' + String.valueOf(myDate.year()); } // Page <apex:outputText value="{!monthyear}" />





I would do this way


<apex:column >

<apex:facet name="header">Registration Date</apex:facet>

<apex:outputText value="{0,date, dd MMM yyyy}">&nbsp;

<apex:param value="{!Opp.Registration_Date__c}" />