title: Convert datetime to binary data type SQL Server
body: <p>I have a value </p>
  
  <pre><code>20 01 01 29 13 11 58 15 46 52 00 00 00 
  </code></pre>
  
  <p>which got migrated to a SQL Server table of column type <code>binary</code> as <code>0x20010129131158154652000000</code>. If we observe it is exact value just prefixed with <code>0x</code>, which is fine. </p>
  
  <p>Now, when I am trying to insert a value which should be current date and time with 6 precision millisecond it is converting to a hexadecimal value like <code>0x00000000000000A87200F31D11</code>. </p>
  
  <p>Please help me find a solution which should give the same time stamp value just by prefixing <code>0x</code> even the SQL Server table column type is binary. That is if am passing the value as <code>2018-01-24 15:08:59.780</code>, it should insert into SQL Server table of column type <code>binary(13)</code> as <code>0x20180124150859780</code></p>