Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. help display time only in vb form from sql dateTime (UDT time)

help display time only in vb form from sql dateTime (UDT time)

Scheduled Pinned Locked Moved Visual Basic
databasecsharphelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AAGTHosting
    wrote on last edited by
    #1

    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)
    
    M 1 Reply Last reply
    0
    • A AAGTHosting

      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)
      
      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups