Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I get the 1st of January and the 31st of December three years ago with VB.Net or C#

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading