Validating dates

Validating dates

HTML5 introduces different opportunities to validate dates. The browsers that understand the date element provide users with handy drop down calendars to pick the dates from. This prevents users from misunderstanding the date format.

The date element is provided with six different ways of defining dates:
Date
Month
Week
Time
date + time
date + time – time zone
To implement the date element you would have to use a polyfill to support it properly.

Description of each data element

1)Date

The format for the date type is YYYY-MM-DD, which means that April 14th 2012 would be represented as 2012-04-14.

2)Month

The format for the month type is YYYY-MM, which means that April 2014 would be represented as 2014-04.

3)Week

Sometimes all you need is a week, and the format for the week type is YYYY-Www, which means that week 14 in 2015 would be represented as 2015-W14.

4)Time

Sometimes you need a specific time and the time type is represented as HH:mm:ss.ss but the seconds are optional. This means that 4.30 p.m. would be represented as 16:30 or if you choose to include seconds, 16:30:23.4

5)Date & Time

The datetime type has a long format: YYYY-MM-DD THH:mm:ss.s and April 14th 2014 would be represented as 2014-04-14 T16:30:23.4