title: How can I convert a .Net Datetime to a T-SQL Datetime
body: <pre><code>MyDataSource.SelectParameters["startDate"].DefaultValue =
                                       fromDate.SelectedDate.Date.ToString();
  </code></pre>
  
  <p>As you can see I am setting the default value of a parameter in my .Net SqlDataSource. I don't think the string is outputting the correct format though. What is the correct format so a T-SQL Datetime will match it properly?</p>
  
  <p>Here are the formats that are outputted right now:</p>
  
  <ul>
  <li>5/1/2009 12:00:00 AM</li>
  <li>5/4/2009 11:59:59 PM</li>
  </ul>
  
  <p><strong>Edit:</strong> Before I had DataSource where it should have been written SqlDataSource</p>
  
  <p>And here is some code</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="MyDataSource" runat="server" ConnectionString="&lt;%$ ConnectionStrings:sampledb %&gt;" SelectCommand="Recording_Select" SelectCommandType="StoredProcedure" OnSelecting="MyDataSource_Selecting"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:ControlParameter ControlID="respondentID" DefaultValue="%" Name="RespondentID" PropertyName="Text" Type="String" /&gt;
          &lt;asp:SessionParameter Name="projectCode" SessionField="proj" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="interviewerList" Name="InterviewerID" PropertyName="SelectedValue" Type="String" /&gt;
          &lt;asp:ControlParameter ControlID="dispCodeList" Name="dispCode" PropertyName="SelectedValue" Type="Int32" /&gt;
          &lt;asp:ControlParameter ControlID="fromDate" DefaultValue="1/1/1900" Name="startDate" PropertyName="SelectedValue" Type="DateTime" /&gt;
          &lt;asp:ControlParameter ControlID="toDate" DefaultValue="1/1/1900" Name="endDate" PropertyName="SelectedValue" Type="DateTime" /&gt;
      &lt;/SelectParameters&gt;
  &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p><strong>Edit:</strong>
  Well, I figured out the problem and it will seem a bit silly. The code was never calling the DefaultValue because there was always a value present. So my only solution was to make a new hidden label control and load the corrected datetime into that. That pretty much did the trick. I don't know how I overlooked that.</p>