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?

Edited 5 Years Ago by lpmike: n/a

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")

Edited 5 Years Ago by jlego: n/a

See if this helps.

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

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")
This question has already been answered. Start a new discussion instead.