We may use either of `sed` or `awk` to completely solve the problem.

---

With `sed`:

 $ sed 's/^.\./0&/' file.txt

When `&` occurs in the replacement part of the substitution command (`s`), it will be expanded to the part of the input line that matches the pattern part of the command.


The regular expression `^.\.` means "*match all lines that starts with (`^`) an arbitrary character (`.`) followed by a literal dot (`\.`)*".


If the line is `1.02.2017 23:40:00`, the pattern will match, and `1.` would be replaced by `01.` at the start of the line.

---

With `awk`:

Building on the partial `awk` code in the question...

This will, as stated, print the second character of each line of input:

 $ awk '{ print substr($0, 2, 1) }' file.txt

We can use the fact that `substr($0, 2, 1)` returns the second character and use that as the condition:

 $ awk 'substr($0, 2, 1) == "." { ... }' file.txt

What goes into `{ ... }` is code that prepends `$0`, which is the contents of the current line, with a zero if the preceding condition is true:

 $ awk 'substr($0, 2, 1) == "." { $0 = "0" $0 }' file.txt

Then we just need to make sure that all lines are printed:

 $ awk 'substr($0, 2, 1) == "." { $0 = "0" $0 } { print }' file.txt

The condition `substr($0, 2, 1) == "."` may of course be changed into a regular expression too (we use exactly the same expression as we used in the `sed` solution):

 $ awk '/^.\./ { $0 = "0" $0 } { print }' file.txt

Some people who thinks "shorter is always better" would write that as

 $ awk '/^.\./ { $0 = "0" $0 } 1' file.txt

(and probably also remove most spaces: `awk '/^.\./{$0="0"$0}1' file.txt`)