title: Creating User Define Function to Convert Dates in SQL Server
body: <p>I know how to convert to date in SQL Server (T-SQL) but how do I create a UDF so that I can call it each time in my code? </p>
  
  <p>Example 1: The below code will format this 20120428 to 04/28/2012</p>
  
  <pre><code>SELECT CONVERT(CHAR(10), CONVERT(DATE, TEST_DATE), 101) AS MY_DATE
  FROM
  MEMBER
  WHERE ISDATE(TEST_DATE) &lt;&gt; 0
  </code></pre>
  
  <p>Example 2: The below code will format this 20120428 to 2012-04-28</p>
  
  <pre><code>SELECT CONVERT(DATE, TEST_DATE) AS MY_DATE
  FROM
  MEMBER
  WHERE ISDATE(TEST_DATE) &lt;&gt; 0
  </code></pre>
  
  <p>Thank for the input!</p>
  
  <p>Guy</p>