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

1 Answer 1


You got the month and day backwards. Try

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


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.

  • 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, 2019 at 0:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .