HTML time and date types

+2 votes
29 views
asked Dec 15, 2012 in HTML by john (4,220 points)

I am using type="time" for my input. Is there a way to set up steps for minutes (00,15,30,45).

Also i have one input with type="date". Is there a way to limit selection date, that uses cant't select some future dates.

 

1 Answer

0 votes
answered Dec 15, 2012 by kalpana (3,995 points)

 

In principle, by HTML5 drafts, you can use the step attribute to set the step size. For input type=time, its value is interpreted in seconds, so for 15 minutes, you would use

<input type=time step=900>

This is currently supported by Opera and Safari, but not Chrome (odd, because some earlier version had support, at least according to my book (literally)).

Similarly, you can set an upper limit for date using the max attribute. There is, however, no concept of “now” in HTML5. You would need to determine the current date when generating the page server-side, or set it client-side with JavaScript (these involve two different interpretations for “current”). Example:

<input type=date max="2012-08-29">

Works on Chrome, Opera, Safari.

 

...