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
MacLeanMacLean 

Formula: Change date format

Currently, I have a field that displays a date as "m/d/yyyy", I need it to display as "YYYY-MM-DD".

 

Is this possible?

 

Thanks, Mac

 

Best Answer chosen by Admin (Salesforce Developers) 
MacLeanMacLean

Its possible through regular formula, just took a little more research.  Here is the solution:

 

(IF(ISBLANK(Complete_Date__c), "",
TEXT(YEAR(Complete_Date__c))+"/"
+TEXT(MONTH(Complete_Date__c))+"/"
+TEXT(DAY(Complete_Date__c))))

All Answers

PrasadVRPrasadVR
I think its not possiable
HariDineshHariDinesh

Hi,

 

I think this is not possible through Standard fields and formulas,

But you can do this with VFP and APEX.

Am sharing code here you can use this IF needed/useful to you

 

Apex Class

public class MyControllerdate {
public Task DateInput {get;set;}
public string sFormattedDate {get;set;}

public MyControllerdate() {
    DateInput = new Task();
}

public void save() {
    Date dInputDate = DateInput.ActivityDate;

    //Format Date
    DateTime dtValue = DateTime.newInstance(dInputDate.year(), dInputDate.month(), dInputDate.day());
    sFormattedDate = dtValue.format('yyyy-MM-dd');

}
}

 VFP Code

<apex:page controller="MyControllerdate">

<apex:form>
    <apex:pageBlock>
        <apex:pageBlockSection>
        <apex:CommandButton value="save" action="{!save}"/>
            <apex:pageBlockSectionItem>
                <apex:outputLabel for="inputDate" value="My Date"/>
                <apex:inputField value="{!DateInput.ActivityDate}" />
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
    <apex:pageBlock>
    <apex:pageBlockSection>
       <apex:outputText value="{!sFormattedDate}" ></apex:outputText>
    </apex:pageBlockSection>
    </apex:pageBlock>
</apex:form>
</apex:page>

 

MacLeanMacLean

Its possible through regular formula, just took a little more research.  Here is the solution:

 

(IF(ISBLANK(Complete_Date__c), "",
TEXT(YEAR(Complete_Date__c))+"/"
+TEXT(MONTH(Complete_Date__c))+"/"
+TEXT(DAY(Complete_Date__c))))

This was selected as the best answer
HariDineshHariDinesh

hi,

This one is Good and Thanks for Sharing this..