0

I am using HTML5 input type date. By default input type="date" allows us to select date in dd/mm/yyyy format. I do not need year. Can I just get date in dd/mm format in my html form? Note that I am using the form in render() method of ReactJS

  • If the year doesn't really matter to you, would it be acceptable for you to just show the current year, and then discard that information later? – Tim Biegeleisen Dec 19 '18 at 14:53
  • 3
    Possible duplicate of [How to hide the year part in Html calendar panel?](https://stackoverflow.com/questions/48680414/how-to-hide-the-year-part-in-html-input-type-date-calendar-panel) – Ivar Dec 19 '18 at 14:54
  • Check out [**Is there any way to change input type=“date” format?**](https://stackoverflow.com/questions/7372038/is-there-any-way-to-change-input-type-date-format) – cнŝdk Dec 19 '18 at 15:07
  • @Ivar I tried putting the js code in componentDidMount(), but it is saving the setting the year as 2018(current year) in input type="date". I totally want to discard the year. Any help would be appreciated – Pooja Chawla Dec 19 '18 at 15:30
  • It will be fine if the year doesn't get displayed in the input type @TimBiegeleisen – Pooja Chawla Dec 19 '18 at 15:31
  • @PoojaChawla That is not possible for `input="date"` [as explained here](https://stackoverflow.com/questions/7372038/is-there-any-way-to-change-input-type-date-format). You'll have to find another way or try to find one of the many plugins that can do this for you. – Ivar Dec 19 '18 at 15:35

1 Answers1

0

Although a vanilla solution can include:

The best way to deal with dates in forms in a cross-browser way at the moment is to get the user to enter the day, month, and year in separate controls ( elements being popular; see below for an implementation), or to use a JavaScript library

what I do in my projects is to format dates with Cleave.js, in order to obtain a experience consistent through browsers and locales.

Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date

Mosè Raguzzini
  • 15,399
  • 1
  • 31
  • 43