title: Problem converting an NVARCHAR column value to datetime format mm/dd/yyyy hh:mmAM or PM using tsql
body: <p>I am working with an audit table that has an nvarchar(255) column that can have many types of different data values based on another field value.  For one of those other field values I'm trying to convert the nvarchar value to a datetime value.  Here is an example of what I'm trying to do:</p>
  <pre><code>declare @d nvarchar(255) = '2022-06-01'
  SET @d = CONVERT(datetime,@d)
  select @d;
  </code></pre>
  <p>The value returned is:  Jun  1 2022 12:00AM</p>
  <p>What I am trying to get is:  06/01/2022 12:00AM</p>
  <p>I did try the code below but I'm missing the 4 digit year and I want the seconds removed but it's a lot closer than the example above:</p>
  <pre><code>declare @d nvarchar(255) = '2022-06-01'
  SET @d = CONVERT(varchar,CONVERT(datetime,@d),22);
  select @d;  
  </code></pre>
  <p>The value returned is:  06/01/22 12:00:00 AM</p>
  <p>What I am trying to get is:  06/01/2022 12:00AM</p>
  <p>Is there a way to accomplish that?  Any help/direction would be greatly appreciated.  Thank you.</p>