The entire problem here (seems to me at first glance to be) a matter of, first, getting the executed command to generate the full datetime value as a string; and, second, interpreting that string. All of which ceases to be a problem when you approach the task using DBI. Now, you can obtain the value directly, i.e. in binary form. And you’re not executing any shell-command to do it, which can very quickly become prohibitive, say in a loop. So, to me, this logic as-conceived definitely should be abandoned, not patched.