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
BantiBanti 

Date field to Text fields

Hi,

     I have date field , suppose i am selecting 4/3/2013 in date field

 

 

i have 3 more fields

 

Date( text) 

Month( Picklist)

Year( Text) 

 

i want to auto populate date field value in to these 3 fields by date,month, year 

 

how can i do this, any help will be appriciated

 

Thanks in Advance.

Banti

Best Answer chosen by Admin (Salesforce Developers) 
Shannon HaleShannon Hale

Hi Banti,

 

So if I understand you correctly, you want to select a date and then put the day part in the Date field, set the Month picklist to the month, and set the Year field to the year?

 

Do you need the Date, Month and Year fields to be editable after the fact, or can they be read only? If they can be read only, you can use formula fields of type Text and set the values to TEXT(DAY(DateField__c)), TEXT(MONTH(DateField__c)), and TEXT(YEAR(DateField__c)). If you wanted to spell out the month instead of showing the number, you could use the following formula instead:

 

CASE(
  MONTH(DateField__c), 
  1, "January", 
  2, "February", 
  3, "March",  
  4, "April",  
  5, "May",  
  6, "June", 
  7, "July", 
  8, "August", 
  9, "September", 
  10, "October", 
  11, "November",
  "December"
)

 

If you need the fields to be editable, you could use a workflow rule with a field update workflow action to set the values of Date and Year to the same formulas above. However, you can't use a formula to set the value of a picklist in a workflow field update; it can only be set to a static value, like "January", so you won't be able to set that without using a trigger. And if you need to do that in a trigger, you'll probably want to set all three fields using the same trigger.

All Answers

Shannon HaleShannon Hale

Hi Banti,

 

So if I understand you correctly, you want to select a date and then put the day part in the Date field, set the Month picklist to the month, and set the Year field to the year?

 

Do you need the Date, Month and Year fields to be editable after the fact, or can they be read only? If they can be read only, you can use formula fields of type Text and set the values to TEXT(DAY(DateField__c)), TEXT(MONTH(DateField__c)), and TEXT(YEAR(DateField__c)). If you wanted to spell out the month instead of showing the number, you could use the following formula instead:

 

CASE(
  MONTH(DateField__c), 
  1, "January", 
  2, "February", 
  3, "March",  
  4, "April",  
  5, "May",  
  6, "June", 
  7, "July", 
  8, "August", 
  9, "September", 
  10, "October", 
  11, "November",
  "December"
)

 

If you need the fields to be editable, you could use a workflow rule with a field update workflow action to set the values of Date and Year to the same formulas above. However, you can't use a formula to set the value of a picklist in a workflow field update; it can only be set to a static value, like "January", so you won't be able to set that without using a trigger. And if you need to do that in a trigger, you'll probably want to set all three fields using the same trigger.

This was selected as the best answer
BantiBanti