Posted By

corydeppen on 06/22/08


Tagged

access vba 2003 vb


Versions (?)

How long ago did something occur


 / Published in: Visual Basic
 

  1. Function whenCreated(dtmCreated As Date) As String
  2.  
  3. Dim lngHoursDiff As Long
  4. Dim lngDaysDiff As Long
  5. Dim lngWeeksDiff As Long
  6. Dim lngMonthsDiff As Long
  7.  
  8. lngHoursDiff = Abs(DateDiff("h", Date, dtmCreated))
  9. lngDaysDiff = Abs(DateDiff("d", Date, dtmCreated))
  10. lngWeeksDiff = Abs(DateDiff("ww", Date, dtmCreated))
  11. lngMonthsDiff = Abs(DateDiff("m", Date, dtmCreated))
  12.  
  13. Select Case lngHoursDiff
  14. Case Is < 24
  15. whenCreated = lngHoursDiff & " hours ago"
  16. Case Is < 48
  17. whenCreated = "Yesterday"
  18. Case Else
  19. Select Case lngDaysDiff
  20. Case Is < 7
  21. whenCreated = lngDaysDiff & " days ago"
  22. Case Is < 14
  23. whenCreated = "Last week"
  24. Case Else
  25. Select Case lngMonthsDiff
  26. Case 0
  27. whenCreated = lngWeeksDiff & " weeks ago"
  28. End Select
  29. End Select
  30. End Select
  31.  
  32. End Function

Report this snippet  

You need to login to post a comment.