Set two DateTimePicker date range to last year - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This code is used when you need to set two DateTimePicker date value to the range of the beginning of the last year and the end of last year. Example: you make a software to track a store sales and you want to know how much in sales you made last year.

In this program, you will learn how to change the value of the two DateTimePicker control: the first one to the beginning of last year and the second one to the end of last year.

DateTimePicker1.Value = Today.Date.AddYears(-1)
DateTimePicker1.Value = DateTimePicker1.Value.Date.AddMonths(-Today.Month + 1)
DateTimePicker1.Value = DateTimePicker1.Value.Date.AddDays(-Today.Day + 1)
DateTimePicker2.Value = Today.Date.AddMonths(-Today.Month + 1)
DateTimePicker2.Value = DateTimePicker2.Value.Date.AddDays(-Today.Day)

last year range

Share This

Home | About | Contact | Privacy Policy

Copyright 2018 - All Rights Reserved.