0

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

6
Contributors
6
Replies
29
Views
4 Years
Discussion Span
Last Post by LeNenne
0

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

0

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))
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.