Darek Kay's picture
Darek Kay
Solving web mysteries

Script crashes before 10 a.m.

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%
08.05.2015
echo %TIME%
 9:34:52,75

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 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
LocalDateTime=20150508093452.386000+120

This pretty much sums it up:

"It's a complete nightmare for a BAT programmer." PA., StackOverflow

Script crashes before 10 a.m.