CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2017
    Posts
    5

    Convert String to DateTime for SQL Server Insert

    I have a string that looks like 2017:10:08 13:01:14 and simply need to convert it into an acceptable DateTime format for inserting into a SQL Server field of type datetime.

    I would prefer to use something simple and flexible like
    Code:
    DateTime.Parse(datevar)
    ...but that is not working. I have also tried
    Code:
    DateTime.ParseExact(datevar, "yyyy:MM:dd HH:mm:tt", Nothing)
    which is not working either. Any help you can provide is appreciated!

  2. #2
    Join Date
    Oct 2017
    Posts
    5

    Re: Convert String to DateTime for SQL Server Insert

    Not sure if this additional code will be helpful...

    Code:
    Dim img As Image = Image.FromFile(FileName)
    Dim dateTaken As String
    Dim dateforinsert As DateTime
    
    Dim pitem As PropertyItem
    
    If img.PropertyIdList.Contains(DATE_TAKEN) Then
                pitem = img.GetPropertyItem(DATE_TAKEN)
                dateTaken = Encoding.UTF8.GetString(pitem.Value, 0, pitem.Value.Length)
                dateforinsert = DateTime.ParseExact(dateTaken, "yyyy:MM:dd HH:mm:ss", Nothing)
     Else
                dateTaken = Nothing
     End If

Tags for this Thread

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

Featured