DateTime.ParseExact yyyy:MM:dd HH:mm:ss problems

Hello folks,

Hopefully quick DateTime.ParseExact question:

Bringing in a string with format "2015:06:11 10:05:19" and trying to change it to a date With:


                                                If Not IsNothing(fDateTaken) Then
                                Dim Dresult As DateTime
                                Dim newformat As String
                                Dim provider As CultureInfo = CultureInfo.CurrentCulture
                                newformat = "yyyy:MM:dd HH:mm:ss"
                                Try
                                    Dresult = DateTime.ParseExact(fDateTaken, newformat, provider)

                                Catch ex As Exception

                                End Try

Open in new window


I get and error message of "Public member 'ParseExact' on type 'Integer' not found." on the line Dresult = DateTime.ParseExact(fDateTaken, newformat, provider)



Any thoughts ?

Thanks

zip
zipnoticAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
You sure you didn't declare a variable named "DateTime" somewhere above this code?
0
David Johnson, CD, MVPOwnerCommented:
Works for me
Imports System.Globalization

Module Module1

    Sub Main()
        Dim fDateTaken As String
        Dim Dresult As DateTime
        Dim newformat As String
        Dim provider As CultureInfo = CultureInfo.CurrentCulture
        newformat = "yyyy:MM:dd HH:mm:ss"
        fDateTaken = "2015:06:11 10:05:19"
        If Not IsNothing(fDateTaken) Then

            Try
                Dresult = DateTime.ParseExact(fDateTaken, newformat, provider)

            Catch ex As Exception

            End Try
        End If
        Console.WriteLine(Dresult)
        Console.ReadKey()

    End Sub

End Module

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
zipnoticAuthor Commented:
Yep, made sure I didn't have "DateTime" declared as a variable (yikes, but you never know...)

Bizarre that it works for you.  I kept getting consistent errors, even after shutting down and restarting VS.

After much frustration I changed it to just get the date instead of the d/t and replaced the ":" with "/"  I pity the poor fool who needs the whole DT....

 
Dim fDateTaken As String = Nothing
Dim Dresult As Date
                                Dim newformat As String
                                fDateTaken = fDateTaken.Split(" ")(0).Replace(":", "/")
                                Dim provider As CultureInfo = CultureInfo.CurrentCulture
                                newformat = "yyyy/MM/dd"
                                Try
                                    Dresult = Date.ParseExact(fDateTaken, newformat, provider)

                                Catch ex As Exception

                                End Try

Open in new window

0
it_saigeDeveloperCommented:
Using David's implementation works for me also.

-saige-
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.