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
thekid12345thekid12345 

How to parse a text string such as Tuesday, February 20th 12:30 PM to 2/20/2017 12:30 PM

Is there a built in function that can help me with this?
Balayesu ChilakalapudiBalayesu Chilakalapudi
You have to convert it from string to date using valueOfGMT(datetimestring) of DateTime class.
Try like this,
 
Map<String,Integer> monthsmap=new Map<String, Integer>{'January' => 1, 'February' => 2, 'March' => 3, 'April'=>4, 'May'=>5, 'June'=>6, 'July'=>7, 'August'=>8, 'September'=>9, 'October'=>10, 'November'=>11, 'December'=>12};

String txt='Tuesday, February 20th 12:30 PM';
String year=System.Today().year();
String month='';
String day='';
string hour = ''; 
string minute = ''; 
string second = '1';

String[] parse=txt.split(' ');
for(String s:parse){
   for(String mm:monthsmap.keyset()){
        if(s.contains(mm)){
             month=monthsmap.get(mm);
        }
   }
   if(s.contains('th')){
      day=s.replace('th','');
   }
   if(s.contains(':')){
      String[] tm=s.split(':');
      hour=tm[0];
      minute=tm[1];
   }
}
string stringDate = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
Datetime myDate = Datetime.valueOfGMT(stringDate);

Let us know if it helps.
thekid12345thekid12345
Hi,

This is throwing an error, line 4.  the error is Illegal assignment from Integer to String. The year must be a Integer but that will conflict with setting it to stringDate