Never mind, the problem was that I had an extra space inserted from the PHP side. This has an extra space behind ~3,2% $batch .= 'set datestr=%d:~6,4%%d:~0,2%%d:~3,2% '."\r\n";
It works fine now as: $batch .= 'set datestr=%d:~6,4%%d:~0,2%%d:~3,2%'."\r\n";