1

I'm looking to know if it's possible to have an input of the type date to have the default year as 2017. All I can do is set a default date which includes the day and the month too:

<input type="date" value="2017-12-21">
<br><br>
<input type="date" value="2017-mm-dd">
<br><br>
<input type="date" value="2017">
<br><br>
<input type="date">

I want it to display the day as dd, the month as mm and the year as 2017.

TylerH
  • 20,799
  • 66
  • 75
  • 101
user7393973
  • 2,270
  • 1
  • 20
  • 58
  • 1
    If you look a [this answer](https://stackoverflow.com/a/6982754/381802), you will see that the input type `date` must be [RFC3339](http://www.w3.org/TR/html-markup/references.html#refsRFC3339) compliant. Which means you must always enter a full and valid date. Why not set it to `2017-01-01`? – erikvimz Dec 21 '17 at 11:21
  • 1
    @Eric That's what I was afraid of since I didn't found anywhere how to do this. It's not too big of a deal, it just would be nice if there was a way since the user can type 2017 and have it what I want as default. The min/max trick in the answers are an ok trick but not what I need as it takes the option to pick another year. – user7393973 Dec 21 '17 at 11:29

2 Answers2

0
   <input type="date"  min="2017-01-01" max="2017-12-30">

Try min and max properties like this. It should work

Umut Yalçın
  • 252
  • 3
  • 9
-2

Try this, as a work around, if all else fails...

Here's the WORKING DEMO

<form>
 <div>
  <input type="date" min="2017-01-01" max="2017-12-31">
 </div>
</form>
Jason Delaney
  • 458
  • 8
  • 21
Subhojit
  • 1,389
  • 8
  • 19
  • 33
  • This is not what he is look for this is what he has sure – Jason Delaney Dec 21 '17 at 11:30
  • Closest workaround but it takes the option to pick other years so unless there's a secret way that nobody knows, the correct answer is Eric's comment. – user7393973 Dec 21 '17 at 11:32
  • Yes, you're right. I thought you're telling about taking 2017 as the default year. Didn't thought about changing the year fact. so just given this solution. mistaken. – Subhojit Dec 21 '17 at 11:48