Bug fixing is probably not the most popular activity amongst software developers. However, sometimes you encounter issues like those:

One day, I’ve got the following ticket assigned:

Script crashes before 10 a.m.

So what exactly went wrong? Our Windows batch script used the current date and time to compose a file name, which was then passed as an argument to a Java application. So far so good. But why does it fail before 10 a.m? Let’s see how Windows handles dates and times:

$ echo %DATE%

$ echo %TIME%

We get a leading zero for days and a space for one-digit hours! This explains why our script failed:

$ java -jar application.jar 2015-05-08- 9-34.txt

So we just replace leading spaces with zeros, right? Nope. The time/date format is country-dependant and can be fully customized… We are supposed to use something like this instead:

$ wmic os get localdatetime /format:list

This pretty much sums it up:

“It’s a complete nightmare for a BAT programmer.”
PA., StackOverflow