help display time only in vb form from sql dateTime (UDT time)
-
How do I display the time only and not the date. I wrote a query that displays the time only, but when I try to display it in a combo box along with the day, today's date also is displayed in the combo box. I tried converting the datetime from sql to varchar and I got the time only. I also tried converting the varchar to string instead of date time in vb.net. I still get today's date. Here is my code.
' declare data table Dim dt As New DataTable() Dim dr As DataRow dt.Columns.Add(New DataColumn("lessonTime", GetType(String))) dt.Columns.Add(New DataColumn("lessonID", GetType(String))) dr(0) = " " & arrWeekDays(Convert.ToInt32(row("less_day")) - 1) & " " & Convert.ToString(row("less_time"))
Here is my query.
SELECT less_id, stud_id, CONVERT(varchar, less_time, 108) AS less_time, less_day FROM tbl_lessons WHERE (less_status = 1) AND (stud_id = @Param1)
-
How do I display the time only and not the date. I wrote a query that displays the time only, but when I try to display it in a combo box along with the day, today's date also is displayed in the combo box. I tried converting the datetime from sql to varchar and I got the time only. I also tried converting the varchar to string instead of date time in vb.net. I still get today's date. Here is my code.
' declare data table Dim dt As New DataTable() Dim dr As DataRow dt.Columns.Add(New DataColumn("lessonTime", GetType(String))) dt.Columns.Add(New DataColumn("lessonID", GetType(String))) dr(0) = " " & arrWeekDays(Convert.ToInt32(row("less_day")) - 1) & " " & Convert.ToString(row("less_time"))
Here is my query.
SELECT less_id, stud_id, CONVERT(varchar, less_time, 108) AS less_time, less_day FROM tbl_lessons WHERE (less_status = 1) AND (stud_id = @Param1)
Work with the date object. Get the date value from SQL as a datetime field and display less_time.toshorttimestring. If you are not happy with the format then fiddle with the format, not the data.