Sixthsense
Sixthsense

Reputation: 1975

Date And Time Picker Custom Format Date Change

My DatePicker is set to custom format dd-MMM-yy

While loading the form its coming with current date. But I would like to see the back date of 2 years and 2 months from the current date.

dtValidFrom.Value = DateTime.Now.AddYears(-2)
dtValidFrom.Value = DateTime.Now.AddMonths(-2)

But the above code is not changing anything in the date and time picker.

I suspect the Custom Format will be the issue.

Any suggestion about how to handle this?

Upvotes: 0

Views: 89

Answers (1)

jmcilhinney
jmcilhinney

Reputation: 54417

That should be:

dtValidFrom.Value = DateTime.Now.AddYears(-2).AddMonths(-2)

Upvotes: 1

Related Questions