8

What would be the accepted convention for displaying a date range in a friendly URL?

For example, in a time tracking application. Instead of using the database's primary key for a specific pay period in the URL, I would like to use something more easily distinguishable to the user.

http://www.mytimesheet.com/11-1-2009-11-14-2009
http://www.mytimesheet.com/period-beginning-11-1-2009

Neither of those seem to cut it, but maybe I'm just being overly critical.

Jason B
  • 85
  • 1
  • 1
  • 4

4 Answers4

8

Have you considered ISO format dates, especially in their compact form: YYYYMMDD, then it should be possible to have:

http://example.com/dates/20091101/20091131

Specifically I don't think there is any accepted convention for this.

Edit: this is about routing as well...

Richard
  • 106,783
  • 21
  • 203
  • 265
  • This seems like the cleanest solution I've seen, and the most straightforward outside of a query string. – Jason B Nov 11 '09 at 13:29
  • 2
    +1. Can include the `-`s too if you want; if you do use hyphens you should *always* be using ISO8601 YYYY-MM-DD ordering. – bobince Nov 11 '09 at 14:48
2

I'd say it's up to you, but I like the idea of

http://foo.com/bar/from/2008/
http://foo.com/bar/from/2008/10/
http://foo.com/bar/from/2008/10/02

Or, it can be combined with something like /between/2008/10/2009/10 and such.

Tamas Mezei
  • 899
  • 6
  • 9
  • I prefer this method, as it makes the address much more 'human readable/explorable' – Jon Hadley Nov 11 '09 at 14:57
  • I'd like to offer an alternate preference to: `http://foo.com/bar/from/2014-09-01/`. It implies a date similar to the written form. Would you say this is more human readable? – Glycerine Sep 08 '14 at 20:06
1

I'd either use something like:

http://www.mytimesheet.com/start/11-1-2009/end/11-14-2009

or

http://www.mytimesheet.com?start=11-1-2009&end=11-14-2009

But what daniel says, you could convert this in a post so you hide it altogether, if that is possible.

Razzie
  • 30,834
  • 11
  • 63
  • 78
0

Personally I think this is the sort of data that is best POSTed, rather than used to specify a route.

(sometimes if the solution seems broken in this way, then maybe the approach is incorrect.)

However, if you really want to specify dates, perhaps you should consider a format that is more likely to be understood in a consistent way in all cultures, such as yyyy-mmm-dd (e.g. 2009-nov-11)

Daniel Robinson
  • 2,165
  • 17
  • 14
  • 1
    POST seems like a really bad idea here, as it would break pretty much any kind of UI exprience (no bookmarking, no reloading without an anoying popup if at all, no back button). A GET query is a lot better for..., well, queries. Only use POST when you're actually changing something (like updating a database record), which should not be allowed to do twice. – falstro Nov 11 '09 at 13:19
  • 1
    Also no sending a URL to a friend/colleague/etc over instant messaging or email, that's something that really bugs me. :) – falstro Nov 11 '09 at 13:25