OuterSpace
OuterSpace

Reputation: 415

How to set today date as default for Material UI datepicker

In my react app, I am using Material UI datepicker. Unfortunately I am not able to set today's date as default date. here is my code:

<TextField 
          id="dateTimeFrom"                                        
          type="date"
          variant="standard"
          defaultValue={new Date()}
          onChange={filterDateFrom}                                            
          label="Start Execution *" color="primary"
          InputLabelProps={{
           shrink: true                                              
           }}
          />

Can you point me to the right solution? enter image description here

Upvotes: 1

Views: 9989

Answers (1)

Priyanka Panjabi
Priyanka Panjabi

Reputation: 441

Try this:

<TextField 
      id="dateTimeFrom"                                        
      type="date"
      variant="standard"
      defaultValue={new Date().getDay()+"-"+(new Date().getMonth()+1)+"-"+new Date().getFullYear()}
      onChange={filterDateFrom}                                            
      label="Start Execution *" color="primary"
      InputLabelProps={{
       shrink: true                                              
       }}
      />

Upvotes: 1

Related Questions