title: Extract date from string and format yyyy-mm-dd in vb.net
body: <p>I'm trying to convert existing vba code into vb.net code.</p>
  
  <p>The purpose is to extract the date from a string and then to format it into mySql style.</p>
  
  <p>My working vba code is:</p>
  
  <pre><code>mData = Format(Left(Trim(Eventi(NuoviEv).innertext), 10), "yyyy-mm-dd")
  </code></pre>
  
  <p>In vb.net I was able to use the following to extract the date; but I wasn't able to format it.</p>
  
  <pre><code>mData = eventi(nuoviev).innertext.substring(0,10).trim()
  </code></pre>
  
  <p>How can I add formatting for "yyyy-mm-dd" onto the vb.net code?</p>
  
  <p>An example of string (value of 'Eventi(NuoviEv).innertext') is:</p>
  
  <pre><code>03/12/2014 - Something happens
  </code></pre>
  
  <p>Is it a waste of resources if I use this?:</p>
  
  <pre><code>mData = Eventi(NuoviEv).innertext.substring(6, 4) &amp; "-" &amp; _ 
      Eventi(NuoviEv).innertext.substring(3, 2) &amp; "-" &amp; _ 
      Eventi(NuoviEv).innertext.substring(0, 2)
  </code></pre>
  
  <p>Thanks to MAC I also got this solution:</p>
  
  <pre><code>mData = Date.ParseExact(eventi(nuoviev).innertext.substring(0,10), "dd/mm/yyyy", nothing).tostring("yyyy-mm-dd")
  </code></pre>
  
  <p>Only a doubt: it seems a little complex, isn't there a simpler  way?
  However, can you indicate the better solution?</p>