Results 1 to 3 of 3

Thread: Time conversion problem

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Time conversion problem

    I'm looking for a way to convert a 5 character time representation to a date object. ie. "0937a" should be "6/16/2010 9:37 AM" or "1215p" should be "6/16/2010 12:15 PM". Thanks for any help...

  2. #2
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Time conversion problem

    I don't have access to vb.net at the moment so here is something from vb6 which you can amend as per your requirement and convert to vb.net

    Code:
    Sub Sample()
        Dim strTime As String
    
        strTime = "0937a"
        
        strTime = Mid(strTime, 1, 2) & ":" & Mid(strTime, 3)
    
        If Right(strTime, 1) = "a" Then
            strTime = Replace(strTime, "a", " AM")
        ElseIf Right(strTime, 1) = "p" Then
            strTime = Replace(strTime, "p", " PM")
        End If
    
        MsgBox Date & " " & strTime
    End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Time conversion problem

    vb.net Code:
    1. Private Function GetDate(ByVal time As String) As Date
    2.     Return Date.Today + Date.ParseExact(time & "m", "hhmmtt", Nothing).TimeOfDay
    3. End Function
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width