DesktopDateTimePicker: where can I change the day #kdsjfksj

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… :frowning:

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
1 Like

Thank you for your help.

That is the first thing I always do. In this case I found nothing.

The LR States:

SelectedDate As DateTime

The DateTime displayed in the control.

Set the selected date to now:

DateTimePicker1.SelectedDate = DateTime.Now

There is no entry for Day, Month, Year nor the others that appears when DateTimePicker.[Tab].

If you’d stop and think, you’d realize those properties are on the DateTime that you provide the SelectedDate.

Using auto complete to guess everything is no way to develop. Especially since auto complete has bugs.

1 Like

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

An example:

DateTimePicker1.SelectedDate = DateTimePicker1.SelectedDate.AddInterval(0,1)
DateTimePicker1.SelectedDate = DateTimePicker1.SelectedDate.SubtractInterval(0,0,DateTimePicker1.SelectedDate.Day)

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, …). :slight_smile:

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:

Maintenant, je vais planter des choux.

My reply, is still valid. :slight_smile:


Don’t be so rude please. I just try to help. :wink: (BTW: Sascha) :smiley:

1 Like

When you say “there is no entry…” are you talking about the Documentation?

Here is what the Documentation says:

So, SelectedDate is a DateTime, if you want to know what the [TAB] should show after SelectedDate.[TAB], then you go to DateTime documentation:

or are you talking of something else?

They are read only… as the title says, I want to change the day # not just read it.

I found DateInterval and it do the trick:

And how you do this is also written in the LR:

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

The LR is certainly not the best and not particularly easy to read, but if you read carefully and take a little more time to do the research in the LR, you will usually find what you are looking for.

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.

1 Like

Var dt As DateTime = dtpick.SelectedDate
Var myDay As Integer = 22
dt = New DateTime(dt.Year, dt.Month, myDay, dt.Hour, dt.Minute, dt.Second, dt.Nanosecond, dt.Timezone)
dtpick.SelectedDate = dt

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:

Constructor Year As Integer, Month As Integer, Day As Integer, hour As Integer = 0, minute As Integer = 0, second As Integer = 0, nanosecond As Integer = 0, timeZone As TimeZone = Nil

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

Yes I am.

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.