Date.valueOf to convert a String to a Date

Date testDate = Date.valueOf('2022-01-01');

System.debug(testDate);


Output - 2022-01-01T00:00:00.000Z


Reference: https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_methods_system_datetime.htm#apex_System_Datetime_valueOf


Visual : https://www.youtube.com/watch?v=ZPrzW9PtMg0

Comments