react-datepicker icon indicating copy to clipboard operation
react-datepicker copied to clipboard

RangeError: Invalid time value on version 4.8.0

Open Epileptic-Experience opened this issue 3 years ago • 8 comments

when using the dependency i get the error mentioned in the tittle on render, I looked through another issues and in stackedOverflow and saw that it was a problem with the format in versions lower than 2.3, however I'm currently using version 4.8.0 and formats described in the documentation,

`**import React, { useState } from "react"; import DatePicker from "react-datepicker";

export type DateSelectorType = { value?: Date, onChange: Function }

const DateSelector = ({ value = new Date(), onChange }: DateSelectorType) => { const [startDate, setStartDate] = useState(value); const [selectedDate, setSelectedDate] = useState(new Date()) const changeDates = (date: Date) => { setStartDate(date) setSelectedDate(date) onChange(date) } React.useEffect(() => { setStartDate(value) },[value]) return ( <div className="DateSelector"> <DatePicker dateFormat={"dd-mm-yy"} selected={startDate} onChange={(date: Date) => changeDates(date)} /> );** }; export default DateSelector`

Epileptic-Experience avatar Dec 12 '22 15:12 Epileptic-Experience

How did you resolved this issue?

awaisg717 avatar Jan 12 '23 12:01 awaisg717

I'm also experiencing issues when providing custom date formats and using a customInput.

https://stackblitz.com/edit/react-ts-n6oswq?file=App.tsx

tabuckner avatar Feb 08 '23 22:02 tabuckner

I was able to resolve this issue by parsing the date like in this comment but now any PM time I choose becomes an AM time.

Edit: If you use selected={new Date(value)} the time is correct. I still can't get AM/PM to show but I'm assuming that's a separate issue.

musicalmacdonald avatar Apr 03 '23 22:04 musicalmacdonald

Update: The above suggestion does not work in Firefox or Safari.

musicalmacdonald avatar Apr 06 '23 15:04 musicalmacdonald

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Jun 07 '24 01:06 github-actions[bot]

I am still having this issue even on a non-range date picker. To solve this,

onChange={value => {
          let dob = moment(value) 
          if (dob.isValid()) {
              setDate(dob.toDate())
          } else {
              const date = new Date();
              setDate(date)
          }
      }}

jvallar avatar Aug 07 '24 02:08 jvallar

Same issue with Safari on iOS and MacOS

CubaJas avatar Sep 26 '24 11:09 CubaJas

Hi Guys, i had the same issue, i solved it like this

<ReactDatePicker selected={(() => { if(passengerSeatInfo?.dob) { return new Date(passengerSeatInfo?.dob); }else { return passengerSeatInfo?.dob } })()} onChange={(e) => setPassengerInfo(prevData => ({...prevData, dob: e}))} />

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] avatar Oct 13 '25 02:10 github-actions[bot]

This issue was closed because it has been stalled for 10 days with no activity.

github-actions[bot] avatar Oct 24 '25 02:10 github-actions[bot]