title: Date and Time Formatting in VB.net and SQL Server
body: <p>I have a table in which data is been logged in 'yy/MM/dd HH:mm:ss' format and my regional setting is '2016-04-02 14:25:15' type. I want to get details in a following query but it is not populating any results</p>
  
  <p>The query I used is</p>
  
  <pre><code>select 
      Date_time, alarm_id, alarm_message 
  from 
      table01 
  where 
      Date_time between '" &amp; DateTimePicker5.Value &amp; "' and '" &amp; DateTimePicker6.Value &amp; "'
  </code></pre>
  
  <p>I also tried using one function which I had written is</p>
  
  <pre><code>Private Function FormatDate(ByVal dat As String) As String
      Dim FTDate As Date
      FTDate = FormatDateTime(Convert.ToDateTime(dat), DateFormat.ShortDate)
      FormatDate = Format(FTDate, "yy/MM/dd HH:mm:ss")
  End Function
  </code></pre>
  
  <p>And used the same again in query as</p>
  
  <pre><code>select 
      Date_time, alarm_id, alarm_message  
  from 
      table01 
  where 
      Date_time between '" &amp; formatdate(DateTimePicker5.Value) &amp; "' and '" &amp; formatdate(DateTimePicker6.Value) &amp; "'
  </code></pre>
  
  <p>Please suggest appropriate answer make sure that I don't want to change my regional setting and on form load event. I've written the following code</p>
  
  <pre><code>      DateTimePicker5.Format = DateTimePickerFormat.Custom
        DateTimePicker5.CustomFormat = "yy/MM/dd HH:mm:ss"
        DateTimePicker6.Format = DateTimePickerFormat.Custom
        DateTimePicker6.CustomFormat = "yy/MM/dd HH:mm:ss"
  </code></pre>
  
  <p>The Table Is In Below Mentioned Format</p>
  
  <pre><code>  **Datetime        V1   P1**
  16/08/29 19:12:24   10  STB-1
  16/08/29 19:12:19   20  STB-1 
  16/08/29 19:12:18   30  STB-1 
  16/08/29 19:09:50   40  STB-1 
  </code></pre>