working on react project using ant design datepicker in which I want pick date from current 30 days before and 30 days after and disable the rest of the dates
Anyone help
function disabledDate(current) {
// Can not select days before today and today
return current 30 && current < moment().endOf('day') ;
}
<DatePicker
format="YYYY-MM-DD HH:mm:ss"
disabledDate={disabledDate}
/>
this code gives current and before that disabled its using moment
Please help
CodePudding user response:
I assume that the arg current is number and you are comparing it to moment().endOf('day') which is object.
Start from there, because for any number that you try to compare to this object will return true, e.g.
-1 < moment().endOf("day") => true
0 < moment().endOf("day") => true
1 < moment().endOf("day") => true
CodePudding user response:
Thanks but got it with this
<DatePicker
className="m-0 p-0 pr-2 pl-2 "
disabledDate={(current) => {
return (
moment().add(-1, "month") >= current ||
moment().add(1, "month") <= current
);
}}
/>
