Zero_LL Zero_LL - 2 years ago 112
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
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