Default to current date time

Hi All

How do I default a DatePicker to the current data/time? Its under an "add" crud page so the default "Value" is ${noteshistory.dt} (which doesn't make sense as it would not exist yet) I'd like to make this current d/t.

Thanks!

You can set default value for notehistory.dt in the page.Load event

It actually makes a lot of sense to set the Value property of Input components (such as a DatePicker) to a property of your model. This makes sure that:

  1. The component displays the value of that property
  2. When the user inputs a different value that property is properly updated

More info about components and properties can be found in the Fundamentals section of Radzen's documentation.

Setting default values is quite simple as @Vinod_Pillai has shown - just assign the property you want to the value you want after the model is instantiated.

Hi @Vinod_Pillai , @korchev

I have set the Value property to DateTime.Now but am getting the incorrect date
image

image

Any suggestions?

Check again @Vinod_Pillai 's response. Do not assign the Value property of the component directly to DateTime.Now as it will no longer update the model property. Make sure to check the Fundamentals help article which shows how to get user input and explains how the Value property of input components work.

ok thanks for your pateient, i have done exactly as suggested and its populating the field.

I have the DateFormat as yyyy-MM-dd but the text box is showing the time

image

How can I exclude the time ?

You can set date format using DateFormat property of the control ex: shown here


otherwise try setting
Set noteshistory.dt to DateTime.Now.Date

Hi
I have already set the DateFormat to yyyy-MM-dd, doing DateTime.Now.Date returns 00:00:00 as the time now.
image

Time still showing despite the DateFormat, not sure why, will live with it...

The yyyy-MM-dd format can't be accepted at the moment. Try with yyyy/MM/dd as a workaround until we address that.