i got this error 'convert datetime to string format yyyymmdd vb.net'

this is my code

Dim ExpDate As String = dgvBlock_Extend.Rows(icnt).Cells("Extend Door & Lift Expiry Date").Value.ToString("yyyyMMdd")

the value is 4/6/2011 12:00 AM

i wnt to convert to format yyyyMMdd

how i'm going to solve this error?

Dim dt As New DateTime(2011, 4, 5)
Dim s As String = dt.ToString("yyyyMMdd")

also, if you import the vb6 references (tools, upgrade vb6 code) type code and convert it to add the simple way, im not sure the reference names

you can do vb6.format(now(), "YYYYMMDD")

Or try with:


See if this helps.

Dim ExpDate As String = CDate(dgvBlock_Extend.Rows(icnt).Cells("Extend Door & Lift Expiry Date").Value).ToString("yyyyMMdd")
commented: .. +3

already solved this error. i'm using this code

dim sDate as date = dgvBlock_Extend.Rows(icnt).Cells("Extend Door & Lift Expiry Date").Value 
    dim ExpDate as string = sDate.ToString("yyyyMMdd")