Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use an HTML input type "date" to collect only a year?

I have a field that is required to collect a year from the user (i.e. a date with a year resolution - for ease of storage I'd prefer to store an actual date value and not a number).

I would like to use the date input UI supported by modern browsers or webshims because its nice and plays well with modern platforms. I couldn't figure out how to get the UI to display only the year. Any ideas?

If there is no platform support, ideally I would like to have a UI something like you can see here if you click "Preview" and then click the top of the widget a couple of times, except in reverse: when you first click the input you get a widget with a list of decades, then you drill down to choose the year, then the UI closes.

like image 706
Guss Avatar asked Jan 08 '16 12:01

Guss


People also ask

How do you display only the year in input type date?

To use year input type, we will be using jQuery to add datepicker. It is used with the text input type. On running the program, only the year will be visible.

How do I get just the year in HTML?

mm-yyyy (07-2022)

How do you select month and year in HTML?

The <input type="month"> defines a month and year control. The format is "YYYY-MM". Tip: Always add the <label> tag for best accessibility practices!


1 Answers

No you can not but you may want to use input type number as a workaround. Look at the following example:

<input type="number" min="1900" max="2099" step="1" value="2016" /> 
like image 120
Blackbam Avatar answered Sep 23 '22 13:09

Blackbam