score:0
Accepted answer
date-fns takes date
as an argument. first you should convert your string date value to a valid date
instance. date
could take several types of value, including iso 8601 date standard, which means you could pass 2022-02-22
string value to date
constructor and it will be valid.
if your string format is not going to change your could do this:
const datestr = '20220211';
const year = datestr.slice(0,4);
const month = datestr.slice(4,6);
const day = datestr.slice(6,8);
const date = new date(`${year}-${month}-${day}`);
and then use date
in date-fns
Source: stackoverflow.com
Related Query
- How to convert Number to Date Using date-fns
- How to convert date to UTC using moment.js
- how to sort an array by string and number and date property using reactjs?
- How to calculate number of tuesday in the selected date range using reactjs?
- How to convert object into Number or string using FormattedNumber to render in react tooltip using REACTJs?
- How to parse ISO 8601 into date and time format using Moment js in Javascript?
- How to convert moment date to a string and remove the moment object
- How to display date in React.js using state?
- how convert date format in javascript reactjs
- How to convert functional component using hooks to class component
- How to get selected date using react-datetime?
- How to test ant design date picker using @testing-library/react?
- How to convert Date format like this Fri Apr 20 2020 00:00:00 GMT+0530 (India Standard Time) to 2020-04-20T00:00:00.000Z in Javascript?
- ReactJS + Material-UI: How to set current date as default value using Material-UI's <DatePicker>?
- How to convert float values in JSON to two decimal place using Javascript
- How we can convert client side rendering react js app to server side rendering using react router 4?
- How to convert design token object to SCSS property using style dictionary?
- Convert date using react-moment
- How to format a number to percentage with two decimals using FormatJs Message Syntax?
- How to convert 2021-07-14T00:00:00.000Z into a standard date in YYYY-MM-DD format
- Material UI Stepper using custom icon deletes the step number. how to add the number or random text back with a custom icon?
- How can I convert a string to a number inside of a useState Hook?
- How to Disable today's date using date pickers - material ui
- How do I get my HTML form date input to only allow specific days of the week to be chosen using JavaScript, React and HTML?
- How to show value, when using date type in TextField?
- how to take out the day name from the input date without using moment js in react
- How to display the date month and year in a specific format using javascript and react?
- How to control number display format using Javascript?
- How to change a let number in react using a button
- How can I convert a class with a constructor to a functional component using React Hooks?
More Query from same tag
- How to chain actions in ReactJS?
- React: How can I call a method only once in the lifecycle of a component, as soon as data.loading is false
- React/Redux - Chaining Actions or combining reducers
- How to make a separate function in react that fetches the data and call each time needed
- React - Trigger form submit using useRef
- React app throwing errors when using 'react-pdf'
- making a dropdown menu from react state
- React server side render: Cannot find module style-loader css-loader
- Can't get componentDidUpdate() stop looping
- Should I use useRef for storing one-time initialised data?
- Setting 2 classNames through props
- Incremental React Game with setInterval: Cannot update during existing state transition
- How to edit a form in wizard and save its state for wizard
- Add style to array element from another object array
- How group props and propTypes to reduce code
- How to render the page based on selected option on the middle part of App, Top and side bar should be static
- How class definition works?
- Unexpected token react-router in express server
- React.js cursor focus issue on chrome
- Data entry field displaying entered values
- Why is this infinite loop happening in the following code? React & useState
- React scroll with antd tabs (scrollIntoView) working for some tabs only
- How to execute an action after the first one is resolved in saga?
- Deploy MERN on heroku cause unexpectable errors
- Why unhandledrejection event can not catch some Error in React?
- How to force App to re-render after mutation?
- How can I handle simultaneous requests for authenticated API, pause all but first while it fetches new access token?
- React hook form popular form with Material UI
- Lodash to sort data in react
- Using `useLocation().search` in useEffect without infinite loop