Hello dear programmers,

Imagine, you’re getting this nice string from this wonderfull object and BOOM: what you get is something completely different… I can see some unhappy faces here! This is the way to get the string as you expected.

Did you know that actually writing the code DateTime.ToString(“dd/MM/yyyy”) or DateTime.ToString(“dd-MM-yyyy”), it’s just the same!

It depends on the Culture of the local machine running the code. I had the joke at work where it works on your machine and not on the Test server. This server was running with a different culture and was displaying 30-10-2016 even if the code was _targetDate.ToString(“dd/MM/yyyy”).

To fix it, I had to do this:

_targetDate.ToString("dd'/'MM'/'yyyy")

Or even bette, use:

_targetDate.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture)

There is always something to learn in every single day.     🙂