Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you markup a date range with the HTML5 time tag?

Tags:

html

date

time

tags

When marking-up dates in HTML5, I know for a single date you should use the <time> tag as follows

<time datetime="2011-04-02">2nd April 2011</time>

But how would you (or should you) markup a date range like "2nd - 4th April 2011"?

Thanks.

like image 419
Steve Wilshaw Avatar asked Feb 08 '11 11:02

Steve Wilshaw


People also ask

What is html5 time tag?

The <time> tag defines a specific time (or datetime). The datetime attribute of this element is used translate the time into a machine-readable format so that browsers can offer to add date reminders through the user's calendar, and search engines can produce smarter search results.

How do you tag a time in HTML?

The <time> HTML element represents a specific period in time. It may include the datetime attribute to translate dates into machine-readable format, allowing for better search engine results or custom features such as reminders. It may represent one of the following: A time on a 24-hour clock.

How do I add date and time to my website in HTML?

Use the <time> tag to add date and time. The HTML <time> tag is used for displaying the human readable date and time.


2 Answers

Marking up date ranges has yet to be settled at this point. (You can see the evolving discussion on date ranges on the WhatWG site.)

Your best bet for now is to simply use the ISO 8601 syntax for date ranges as the datetime value in a time tag. In short, just separate the two values with a forward slash.

For example, the 2nd to the 4th of April, 2011 would be:

<time datetime="2011-04-02/2011-04-04">2nd&ndash;4th April 2011</time> 

Here's a simpler example representing 2000-2010:

<time datetime="2000/2010">2000&ndash;2010</time> 

Remember to use an En dash between your dates for proper presentation.

like image 187
Christian Avatar answered Sep 22 '22 02:09

Christian


It would be nice if <time> had a nice way of representing ranges, but you have to do something like this instead:

<time datetime="2011-04-02">2nd</time> - <time datetime="2011-04-04">4th April 2011</time> 
like image 40
dogbane Avatar answered Sep 21 '22 02:09

dogbane