Link to home
Start Free TrialLog in
Avatar of zipnotic
zipnoticFlag for United States of America

asked on

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
Avatar of kaufmed
kaufmed
Flag of United States of America image

You sure you didn't declare a variable named "DateTime" somewhere above this code?
ASKER CERTIFIED SOLUTION
Avatar of David Johnson, CD
David Johnson, CD
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zipnotic

ASKER

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

Using David's implementation works for me also.

-saige-