0

I'm not sure why this is happening.

When I run

System.Debug(DateTime.valueOf('2019-14-11 10:55:46 pm'));

in Execute Anonymous I'm expecting it to return the same date but in a DateTime.

However, now the date that it is returning is

2020-02-11 15:55:46

2

You got the month and day backwards. Try

System.Debug(DateTime.valueOf('2019-11-14 10:55:46 PM'));

SPECS

enter image description here

Notice it is counting Month 14 of 2019 which puts you in February of 2020. This might be counter intuitive and you might have expected an error saying month can't be greater than 12 but because of how parse() and valueOf() work, it just calculates based on what you pass it.

1
  • That was helpful. I was confused because I had been using a 11/6/2019 string and it appeared to be working correctly. – thinker Nov 15 '19 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.