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
mw6mw6 

Formula to convert text into a Date

How to write a salesforce formula to convert the field Date_of_Withdrawal_String__c (text) field which has he data as "2017-04-30 00:00:00" into a Date field to show the date as 30/04/2017.
Best Answer chosen by mw6
Pranav ChitransPranav Chitrans
Hi,

IF(DAY(DateValue(Date_of_Birth__c)) < 10, TEXT(DAY(DateValue(Date_of_Birth__c))), '0'+TEXT(DAY(DateValue(Date_of_Birth__c)))) +'/'+ IF(MONTH(DateValue(Date_of_Birth__c)) < 10, TEXT(MONTH(DateValue(Date_of_Birth__c))), '0'+TEXT(MONTH(DateValue(Date_of_Birth__c)))) +'/'+ TEXT(YEAR(DateValue(Date_of_Birth__c))), null)

Please ignore brackets or comma as i have writter in notepad, plz correct the syntax if it have any error.

Or you can also go with the simple formula by using DATEVALUE(Date_of_Withdrawal_String__c ) but it will give the format as "MM/DD/YYYY"

Hope this will help!

All Answers

Sanket Supe 35Sanket Supe 35
Use  DATEVALUE(<text filed value>) to convert into Date. 
It returns a date value for a date/time or text expression.

Refer this link : https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_variables_functions.htm
Pranav ChitransPranav Chitrans
Hi,

IF(DAY(DateValue(Date_of_Birth__c)) < 10, TEXT(DAY(DateValue(Date_of_Birth__c))), '0'+TEXT(DAY(DateValue(Date_of_Birth__c)))) +'/'+ IF(MONTH(DateValue(Date_of_Birth__c)) < 10, TEXT(MONTH(DateValue(Date_of_Birth__c))), '0'+TEXT(MONTH(DateValue(Date_of_Birth__c)))) +'/'+ TEXT(YEAR(DateValue(Date_of_Birth__c))), null)

Please ignore brackets or comma as i have writter in notepad, plz correct the syntax if it have any error.

Or you can also go with the simple formula by using DATEVALUE(Date_of_Withdrawal_String__c ) but it will give the format as "MM/DD/YYYY"

Hope this will help!
This was selected as the best answer