Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

/> enter image description here Can you help me please?

like image 822
amirhossein Avatar asked Sep 01 '25 10:09

amirhossein


1 Answers

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

like image 71
Arie Aditya Avatar answered Sep 02 '25 23:09

Arie Aditya