function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vishal_ThoriyaVishal_Thoriya 

how to format the date;

i am having issue with date field.

 

i have one field of type Date in my custom object. and i am storing the date value in it successfully.

 

here is my code:

 

public Date agendaDate2; // user name which will be provided by user   

public Date getAgendaDate2()   

{       

return agendaDate2;   

}   

public void setAgendaDate2(Date dateValue)   

{

       agendaDate2= dateValue;   

}

 

i am showing date value in <apex:inputText> my VF page

 

but it shows the "Fri Nov 18 00:00:00 GMT 2011" in this format.

 

i want to show this date in  12/11/2011 format.

 

show how can i do that ?

 

please help i am newbie in salesforce.

 

any kind of help will be greatly appriciated.

 

thanks in advance...

Vishal

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Baktash H.Baktash H.

All Answers

Baktash H.Baktash H.
This was selected as the best answer
Jim BoudreauxJim Boudreaux

He is asking how to format the value of an INPUTTEXT field, your solution is for an OUTPUTTEXT field, therefore you have not actually answered his question.

Alex Trenchard-SmithAlex Trenchard-Smith
Yes, formatting inputtext is a different issue. Outputtext can use the param tag, but not inputtext.
CurryMan85CurryMan85

The way that I ended up using to do this solves the issue, but was a little complicated.  First, give your apex:inputtext an id.

<apex:inputtext id="myDateId" value="obj.datefield__c" />

Next, in your visualforce controller, create a public string to be used on your VF page.
public string getMyFormattedDate(){
        string output = '';
        if(obj.datefield__c != null){
            DateTime myDate = obj.datefield__c;
            output = myDate.Month()+'/'+myDate.Day()+'/'+myDate.Year();
        }
        return output;
    }
The function above gets the object that you are referencing in the page controller (assuming the name used is 'obj') and will either return a formatted string or an empty string.

Next, using jQuery, create a document.ready function:
 
$(document).ready(function() {
            if('{!MyFormattedDate}' != ''){
                var d = '{!MyFormattedDate}';
                $( '[id$=myDateId]' ).val(d);
            }
});

It's a 3-step process, but it works.  I used it for a calendar using jQueryUI (http://jqueryui.com/datepicker/" target="_blank).