title: SQL Server : same CONVERT statement has to use different styles on servers
body: <p>I tried to execute the below code snippet on two different machines. Both of them have SQL Server 2012 installed and both collations are <code>SQL_Latin1_General_CP1_CI_AS</code>. </p>
  
  <p>Interestingly on one of the machines the style parameter for <code>CONVERT</code> function needs to be set to 103 otherwise I get</p>
  
  <blockquote>
    <p>Conversion failed when converting date and/or time from character string.</p>
  </blockquote>
  
  <p>whereas on the other machine, I have to use style 101 otherwise I will get that same error. </p>
  
  <p>I did some googling and I suspected this behavior somewhat relates to the system locale and language settings but I could be wrong.</p>
  
  <p>Code snippet:</p>
  
  <pre><code>SELECT 
      CONVERT(datetime2(0), LEFT(name, 11) + '' + replace(convert(char(5), cast(replace(RIGHT(LEFT(name, 22), 10), '.', '') as datetime), 108), ':', ':'), 101)
  FROM 
      #FileList
  </code></pre>
  
  <p>Sample rows from #FileList:</p>
  
  <pre><code>01/12/2016  03:27 p.m.           610,304 0.mdb
  30/05/2014  07:43 p.m.           438,274 1.mdb
  03/06/2014  02:52 a.m.        14,921,730 10.mdb
  31/05/2014  10:35 a.m.        11,120,642 12.mdb
  31/05/2014  01:52 a.m.           438,274 13.mdb
  </code></pre>
  
  <p>This is how <code>#FileList</code> gets built:</p>
  
  <pre><code>SET @cmd = 'dir '+@DirectoryPath+'*.mdb /b'
  INSERT INTO #FileList
  EXEC xp_cmdshell @cmd;
  </code></pre>
  
  <p>Any help will be deeply appreciated.</p>