'how to get only date in material ui datepicker react?
I use the Material-UI pickers library to get the date And I just want to get the date like this 17/07/2021
But I get both the date and the time like this Sat Jul 17 2021 12:21:00
const [getDate, setGetDate] = useState(new Date());
<DatePicker
value={selectedDate}
format="MM/dd/yyyy"
minDate={new Date()}
onChange={handleDateChange}
label="Date"
size="small"
required
fullWidth
inputVariant="outlined"
animateYearScrolling
Solution 1:[1]
You can use formatter like moment for your case, something like this:
import moment from "moment";
...
let date = getDate; // value from your state
let formattedDate = moment(date).format('DD/MM/YYYY');
console.log(date) // before: Sat Jul 17 2021 12:21:00
console.log(formattedDate) // after: 17/07/2021
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Arie Aditya |

