I know it is as simple as it is, I've search around the internet and I came up with nothing. Maybe I don't know what to search for.

Basically my datetimepicker format is set to year only.
My string is "2009"
I want the datetimepicker-year to set as the year in string

StrYear = "2007"
Dim YearStart As Date = CType(StrYear , Date).Year

DateTimePicker1.CustomFormat = "yyyy"
DateTimePicker1.Value = YearStart

Error states that conversion of String "2007" to type Date is not valid

Re: [URGENT]Convert String("2009") to Date(Year) 80 80
Dim StrYear As String = "1.1.2007"
        Dim YearStart As Date = Convert.ToDateTime(StrYear)
Re: [URGENT]Convert String("2009") to Date(Year) 80 80

Use ParseExact

Dim dt As Date
 Dim str as String  = "2002"
 dt = Date.ParseExact(str, "yyyy", Nothing)
 DateTimePicker1.Value = dt
Re: [URGENT]Convert String("2009") to Date(Year) 80 80

Thank you GeekByChoice and Adatapost for your replies.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.