Results 1 to 3 of 3

Thread: [RESOLVED] Convert/Compare text to date time

  1. #1

    Thread Starter
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,254

    Resolved [RESOLVED] Convert/Compare text to date time

    Is there an easy way to parse a date time from a string like, "12 Jan 11:15 am" ? I'm having a hard time figuring out how I could just convert that into a date so I can compare it to Now, I need to figure out if it is older then 1 hour from the current time.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    9,677

    Re: Convert/Compare text to date time

    Try:
    Code:
    Dim dtString As String = "12 Jan 11:15 am"
    Dim dt As Date
    
    If DateTime.TryParseExact(dtString, "dd MMM h:mm tt", Globalization.CultureInfo.CurrentCulture, Globalization.DateTimeStyles.None, dt) Then
        'Proper format
    Else
        'Invalid format
        Console.WriteLine("Invalid format.")
    End If

  3. #3

    Thread Starter
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,254

    Re: Convert/Compare text to date time

    Thanks!

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