Hi @jn93 ,
We will use tokenization instead of string parsing.
The fileDateTime variable is of DateTime data type. It will contain the correct value.
c#
void Main()
{
//string FilenameWithoutExt= "RL_TB_COMCN_TMI_20220801_0000";
string FilenameWithoutExt= "RL_TB_COMCN_TMI_20220801_0000 2";
// break string into a string arrays of tokens
string[] tokens = FilenameWithoutExt.Split('_');
string dateValue = tokens[tokens.Count()-2] + tokens[tokens.Count()-1];
try
{
fileDateTime = DateTime.ParseExact(dateValue, "yyyyMMddHHmm", CultureInfo.InvariantCulture);
}
catch (Exception ex)
{
fileDateTime = DateTime.Parse("1900-01-01");
}
}