Link to home
Start Free TrialLog in
Avatar of RadhaKrishnaKiJaya
RadhaKrishnaKiJaya

asked on

Convert String to date

Hi Experts,

I have a date in string format. I want to display it in a date picker control. I am using the following code.

Dim Stk_Date As String = "20140713"
Dim dt As DateTime = DateTime.Parse((Stk_Date).ToString("yyyy-MM-dd"))

I am getting the error  "Unable to cast object of type "System.string" to type "system.IFormatProvider"  "

Thank you.
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

>>Dim Stk_Date As String = "20140713"

That is already a string, using the ToString doesn't make sense.  Where do you get this value of 20140713 from?
Avatar of louisfr
louisfr

I think you misplaced a parenthesis:
Dim dt As DateTime = DateTime.Parse((Stk_Date)).ToString("yyyy-MM-dd")

Open in new window

Avatar of RadhaKrishnaKiJaya

ASKER

Thank you for your reply. Date is in the database in string format.

Dim Stk_Date As String = Reader.Item("STK_DATE")
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland 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
It Worked!!! Thank you very much for your help.