The Apex compile error “Illegal assignment from String to Datetime” means you tried to put a String value into a Datetime variable or field, for example Datetime closeTime = closeText;. Apex never converts text to a Datetime automatically. Fix it by converting explicitly: Datetime.valueOf('2026-10-06 14:30:00'), Datetime.valueOfGmt(...) or Datetime.newInstance(...).
The same error appears for other types, such as “Illegal assignment from String to Decimal” or “to Date”. I reproduced the error in the Developer Console of a Salesforce Developer Edition org and tested every conversion method, including the formats that fail at runtime and the time-zone shift most tutorials don’t mention.