Hi

I am going to be crazy

I have a txtbox with 1950-04-23

How can I extract just 1950 from that box and
take the pc's date ( as today is 2013-04-23) to a label.caption and the result shall be
63 years in the labels caption.

Lenny

Recommended Answers

All 6 Replies

Use Left$ to get the substring, starting from the first character, with a length specified by you.

If you do

Dim fields() As String = TextBox1.Text.Split("-")

assuming that you, in fact, have a date entered in the form YYYY-MM-DD then

fields(0) will contain the YYYY part
fields(1) will contain the MM part
fields(2) will contain the DD part

This will work even if the month and day parts do not have a leading zero. Then to do the math you can do

Diim diff As Integer = Now.Year - CInt(fields(0))

Dim year as Variant
year = Format("1950-04-23",yyyy)

try this ..

Try :

MsgBox Mid$(Text1.Text, 1, 4)

Try:

MsgBox Split(Text1.Text, "-")(0)

hope this helps you . . .

Thanks a lot

Be a part of the DaniWeb community

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