3

Possible Duplicate:
How do I calculate relative time?

Given a DateTime object, what's the most elegant way you've found of converting it to a human friendly string. Something like this:

(Future)

"Tomorrow"
"[1|2|3|4|5|6] days from now."
"Next week"
"Next month"

(Past)
"[1|2|3|4|5|6] days ago."
"Last week"
"Last month"

Thanks.

Community
  • 1
  • 1
Scott Klarenbach
  • 37,171
  • 15
  • 62
  • 91
  • 1
    This is effectively a duplicate of question 11: http://stackoverflow.com/questions/11/how-do-i-calculate-relative-time – jason Oct 15 '09 at 00:02

2 Answers2

1

It's not necessarily the most elegant solution, but this blog article, as well as the the first comment, solve the problem as it pertains to dates in the past. (Copying and pasting the first comment requires replacing the fancy double quotes with plain-old double quotes.)

G-Wiz
  • 7,370
  • 1
  • 36
  • 47
0

Stack Overflow just uses cascading if-thens I believe. Can't find the post right now (it's either here or on meta).

EDIT: Jason found it. Link in the comments on the question.

John
  • 15,990
  • 10
  • 70
  • 110