Zero_LL Zero_LL - 1 year ago 98
C# Question

C# Converting current Year to two digits

I'm trying to get the the last two digits of year like,
2016 to 16 only.
When you click on the

date picker
and choose a date I want to print it to a
textview
with only the last two digits of the year.

Thank you.

the last two digits are displaying when the form loads but couldn't make get it when datetimepiker value changes

private void RegisterSMS_Load(object sender, EventArgs e)
{

idyr.Text = DateTime.Now.Year.ToString().Substring(2);

}

private void regdate_ValueChanged(object sender, EventArgs e)
{
idyr.Text = regdate.Text.ToString().Substring(2);
}

Answer Source

Try this:

yourTextBox.Text = DateTime.Now.Year.ToString().Substring(2);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download