ajeesh_ed ajeesh_ed - 7 months ago 16
Vb.net Question

How to set the default value in datetimepicker as previous month

I have my VB.net program with a

datetimepicker
and the custom format of which is
MM/yyyy
. I want the default value at application startup in the
datetimepicker
as previous month and I don't care whatever day it shows(it can be any day of previous month of the same year). Using
DateTimePicker.Value = CDate(Now.Date.AddDays(-(Now.Day)))
give me the value I want but how can I set it as the default value at application startup?

Answer

I got the answer working fine. adding the following code to form load event served my purpose

Dim dt = DateTime.Now.AddMonths(-1) 
me.DateTimePicker.Value = dt

Thanks plutonix for your help.

Comments