Date and Time Formatting in VB.net and SQL Server -


i have table in data been logged in 'yy/mm/dd hh:mm:ss' format , regional setting '2016-04-02 14:25:15' type. want details in following query not populating results

the query used is

select      date_time, alarm_id, alarm_message       table01       date_time between '" & datetimepicker5.value & "' , '" & datetimepicker6.value & "' 

i tried using 1 function had written is

private function formatdate(byval dat string) string     dim ftdate date     ftdate = formatdatetime(convert.todatetime(dat), dateformat.shortdate)     formatdate = format(ftdate, "yy/mm/dd hh:mm:ss") end function 

and used same again in query as

select      date_time, alarm_id, alarm_message        table01       date_time between '" & formatdate(datetimepicker5.value) & "' , '" & formatdate(datetimepicker6.value) & "' 

please suggest appropriate answer make sure don't want change regional setting , on form load event. i've written following 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" 

the table in below mentioned format

  **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  

this tricky solution. since year kept 'yy' in backend,following assumptions.

if year part of database field between 00 16 ,need consider 2000 2016. remaining values script consider year 1917 1999 .

can try below script.

select date_time, alarm_id, alarm_message  table01          case when left(date_time,2) between 00 , right(year(getdate()),2) convert(datetime,'20'+date_time)         else convert(datetime,'19'+date_time) end between '" & datetimepicker5.value & "' , '" & datetimepicker6.value & "' 

Comments