Datepicker date property examples

I was wondering what we can put into the datepicker date property box in the design display, apart from ‘now’?

I would like to use a default date of 3 months time (or say +90 days), rather than ‘now’

For example, this doesn’t work:
date.today()+timedelta(days=90)

Thanks!

Looking at the reference documentation, I think
I might need to do this in the code view. If so, is it possible to create the date picker in code view and keep the other components in design view?
I haven’t yet built a form purely out of code view or tried to do both design and code views…

You can add days to the DatePicker’s date in the following way:

import datetime

self.date_picker_1.date = datetime.date.today() + datetime.timedelta(days=90)

You mentioned that something similar didn’t work, but it wasn’t clear to me what specifically was going wrong. Perhaps you tried adding that code in the design view. In that case, as you’ve seen, that will not work. You can easily change it in the code view though.

You can create any component by using code or by dragging and dropping from the design view. Of course you often will want to do a mixture of both, and this is fine. If you are just looking to have more control over the DataPicker’s date, you can drag the DatePicker onto the Form and change the date in the code view (perhaps during the init).

Let me know if this helps.

1 Like

Thank you I will try this tomorrow and update my reply. I’m sure it will work!