I need to automatically prefill two Datepickers in VB/Winforms in code that should have the 1st day of the year and the last day of the year as their values, but always 3 years ago.
So for 2022 it should be 2019/01/01 and 2019/12/31.
How could I achieve that?
>Solution :
new DateTime(DateTime.Now.Year - 3, 1, 1) will give you the first day and
new DateTime(DateTime.Now.Year - 3, 12, 31) will give you the last day
These expressions give you the dates you need. The correct place to assign them to the date pickers is either in the form constructor (after Initalize()) or in the Form.Load event.