Posted By

joeydi on 02/19/09


Tagged

date function vbscript


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Barlon


TimeAgo Function


 / Published in: ASP
 

  1. Function TimeAgo(dtField)
  2. days = DateDiff("d", dtField, Now)
  3. If days > 365 Then
  4. years = DateDiff("yyyy", dtField, Now)
  5. If years = 1 Then
  6. ago = "Expired " & years & " year ago"
  7. Else
  8. ago = "Expired " & years & " years ago"
  9. End If
  10. ElseIf days > 30 Then
  11. months = DateDiff("m", dtField, Now)
  12. If months = 1 Then
  13. ago = "Expired " & months & " month ago"
  14. Else
  15. ago = "Expired " & months & " months ago"
  16. End If
  17. Else
  18. ago = "Expired " & days & " days ago"
  19. End If
  20. TimeAgo = ago
  21. End Function

Report this snippet  

You need to login to post a comment.