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
Jeffrey OBrien 7Jeffrey OBrien 7 

Converting text date into actual date

Hi everyone,

I'm trying to convert a text field with a date like "March 23, 2015" into a date field to read 3/23/2015. 

Any help would be much appreciated!
ANUTEJANUTEJ (Salesforce Developers) 
Hi Jeffrey,

As mentioned in the link https://help.salesforce.com/articleView?id=notes_on_changing_custom_field_types.htm&type=5 there is a chance to loose data when you change type of a field if there is existing data and for an alternative you could try using the below implementation:

https://developer.salesforce.com/forums/?id=9060G000000UYWHQA4

I hope this helps and in case if this comes in handy can you please choose this as the best answer so that it can be useful for others in the future.

Regards,
Anutej
John KlokJohn Klok
Hello OBrien,

In below article example given for date/time function please refer.

https://help.salesforce.com/articleView?id=formula_using_date_datetime.htm&type=5

Kindly mark this as solved if the reply was helpful.

Thanks.
Alain CabonAlain Cabon
Apex can format a datetime with any format like java but cannot parse any date (only two formats are allowed: the format of the user locale and the standard date format “yyyy-MM-dd HH:mm:ss” in the local time zone).

So you need to create some code to parse the date  March 23, 2015 with a regular expression and to capture the groups but that becomes quickly complicated if you can have many languages. Otherwise, it is simple with ([^ ]+?) ([0-9]+)?, ([0-9]+)

https://regex101.com/

User-added image


if (group1 == 'January') { month = 1; } else if (group1 == 'February') { month = 2; } else if (group1 == 'March') { month = 3; } ...

 3/23/2015 = month + '/' + group2 + '/' + group3