I received the following task: turn "dd/mm/yyyy hh:mm:ss" time to "yyyy.mm.dd hh:mm" format.
I was hoping that a simple Format(activecell.value, "yyyy.mm.dd hh:mm") would help, but. In some cases it works. However, in some special cases, it doesn't. When the day is between 01-12 (interchangeable with months!), then it messes up the days with months. (Probably because of US style date format.)
For example, original text string: 04/06/2013 09:00:00
Expected: 2013.06.04 09:00
Result: 2013.04.06 09:00 (day and month have been swapped)
I tried to overcome it by formatting the input, I gave it a "dd/mm/yyyy hh:mm:ss" custom format. Didn't help, it still swaps the day and the month.
So I have no ideas anymore, but regular expressions. Date format is always the same so just moving the parts of the string would be okay. However, I don't know how that works and google searching brings up confusing results.
Can anyone help me? Of course if there is a more elegant way to do it, that's also welcome.
dd/mm/yyyy hh:mm:ss
format while the bad dates are inmm/dd/yyyy hh:mm:ss
. What happens if you format all of them asmm/dd/yyyy hh:mm:ss
? Do all the dates change, or only the good dates change? – Jerry