title: Convert sql function to c#
body: <p>Hi all I am having an sql function where some part of it is used to convert varchar to datetime:</p>
  
  <pre><code>IF @dt IS NULL
      SET @dt = GETDATE();
  
  SET @PDate = CONVERT(DATETIME, @PValue + '-' + CONVERT(NVARCHAR(4),YEAR(@dt))); 
  IF @PDate &gt; @dt
      SET @Year = YEAR(@dt) - 1;
  ELSE
      SET @Year = YEAR(@dt);
  
  RETURN (SELECT CONVERT(DATETIME, @PValue + '-' + CONVERT(NVARCHAR(4),@Year)));
  </code></pre>
  
  <p>Can some one help me?</p>
  
  <p>My value of <code>@PValue</code> is <code>01-APRIL</code>.</p>
  
  <p>I just declare Datetime as follows in my C# code:</p>
  
  <pre><code>DateTime? dt=null;
  
  if(!(dt.HasValue))
      dt=DateTime.Now;
  </code></pre>
  
  <p>But after this I was confused to do the remaining.</p>