You need to sign in to do that
Don't have an account?
Admin User 10161
Convert a String to Datetime
Hi there,
When I try to convert String to Datetime in Apex via the following code:
Do you know how to fix that?
Best regards,
When I try to convert String to Datetime in Apex via the following code:
Integer randomNumber = Integer.valueOf((Math.random() * 29))+1; Datetime dt = Datetime.parse('6/'+randomNumber+'/2020');I have this error message: System.TypeException: Invalid date/time: 6/20/2020
Do you know how to fix that?
Best regards,
Datetime dt = Datetime.parse('6/'+randomNumber+'/2020, 00:00 AM');
or you can use date parse method
Date dt = Date.parse('6/'+randomNumber+'/2020');