How can I set the date input field in HTML like as (mm-yyyy (07-2022))

85 Views Asked by At

I want to show only the month and year in The input field of HTML (mm-yyyy (07-2022)). Month Should be Number. I am using HTML, CSS, JavaScript, and react.

I am trying on React Project.

2

There are 2 best solutions below

1
E-housma Mardini On

To create a date input field in HTML with a specific format, you can use the input element with the type attribute set to "date" and the pattern attribute set to the desired format. For example, to create a date input field with the format "mm-yyyy", you can use the following code:

<input type="date" pattern="mm-yyyy">

This will create an input field that allows the user to enter a date in the "mm-yyyy" format. The user will be able to select a date using a calendar interface or type the date manually. The input will be automatically validated to ensure that it is in the correct format.

Note that the pattern attribute is not supported by all browsers, so you may want to consider using a JavaScript library or plugin to create a custom date picker if you need to support older browsers.

0
E-housma Mardini On

You can use DatePicker Because some Browsers doesn't support pattern parameter

Please check out the following bşog about mm-yyyy in DatePicker Jquery

https://qawithexperts.com/article/bootstrap/showing-month-and-year-only-in-bootstrap-datepicker/292