I even copy the DesktopDateTimePicker text page and paste it in TextEdit, then search for day:
there is no property with that name.
I do not searhced for Month or Year.
How do I change the Day # in code (specifically in a Loop).
More, when I set the last day of the month, adding 1 to the Day number goes to the first day of the next Month ?
That is the prefered code Gemini gave me:
Dim d As New Date
d.Year = MyDateTimePicker.Date.Year // Keep the same year
d.Month = MyDateTimePicker.Date.Month // Keep the same month
d.Day = 15 // Set the desired day (e.g., the 15th)
MyDateTimePicker.Date = d
Please, when finished to laugh, give me in answer.
Searching in Vain may be a good title for a song…
Did you try looking at what DateTimePicker offers on the documentation?
See if this works for you:
Dim d As New Date
d.Year = MyDateTimePicker.SelectedDate.Year // Keep the same year
d.Month = MyDateTimePicker.SelectedDate.Month // Keep the same month
d.Day = 15 // Set the desired day (e.g., the 15th)
MyDateTimePicker.SelectedDate = d
Better do the following. Add 1 Month to the SelectedDate, then set the Day of the Month to 1 and then subtract 1 Day. This way you would get a more reliable last day of the currently selected month.
Because thats not how autocomplete works. Don’t press Tab after just a Class Name. Instead press Tab after your Object (DateTimePicker1 instead of just DateTimePicker). Then you will see a full autocomplete List and there the SelectedDate property. Pick the SelectedDate Property, add a . and then you will get a proper autocomplete List for it (incl. Day, Month, …).
I forget to write SelectedDate; the sentence lust be read as:
There is no entry for Day, Month, Year nor the others that appears when DateTimePicker.SelectedDate.[Tab].
Sasha, if you read my last post, you would noticed “SelectedDate” entry of the Language Reference…
As you can see, reading it carefully, you will notice there nis no indication about a possible “Ectension”. To be clear, here’s the autocomplete:
… If you’re going to change a date, use AddInterval, the + operator, SubtractInterval or the - operator as these will handle things like leap years, time zone differences and more.
I used Date instead of DateTime (example above) as it can be used to assign a Date to DesktopDateTimePicker.SelectedDate and I think you are more familiar with Date than DateTime and will work for what you want.
If you prefer to go with DateTime, then you can create a new DateTime with a Constructor or use DateInterval.
DateTime objects are immutable. You cannot change a DateTime, only create a new DateTime with a different date. For that you can use AddInterval or SubtractInterval, or you could create a new object from scratch using a constructor:
I found my code using DateInterval and modifying the date:
Var oneDay As New DateInterval
Dim New_Date As New DateTime(DateTimePicker1.SelectedDate)
oneDay.Days = 1 // 1 day interval
New_Date = DateTimePicker1.SelectedDate + oneDay
// Set the new date
DateTimePicker1.SelectedDate = New_Date
This is based on an example I adapted,(using to change month and year) I found it here: DateTime.AddInterval
In my original code, I checked DatePicker1 before assigning it to New_Date.
Or using Date (maybe you are more familiar with that?):
Dim New_Date As New Date(DateTimePicker1.SelectedDate)
New_Date.Day = New_Date.Day + 1 // add 1 day
// Set the new date
DateTimePicker1.SelectedDate = New_Date
I was in API 2 because of the picker, and i wanted to stay on the same road.
If was easier with Original API than the "like the other development tool” API. (a Google search on DateTimePicker or so shows entries from many other development tools).
PS: when you click in the day value of the DateTimePicker and reach the last day of the month, another click goes back to the first day of the month without changing the month number.
It’s a choice.