/ Published in: Visual Basic
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Function whenCreated(dtmCreated As Date) As String Dim lngHoursDiff As Long Dim lngDaysDiff As Long Dim lngWeeksDiff As Long Dim lngMonthsDiff As Long lngHoursDiff = Abs(DateDiff("h", Date, dtmCreated)) lngDaysDiff = Abs(DateDiff("d", Date, dtmCreated)) lngWeeksDiff = Abs(DateDiff("ww", Date, dtmCreated)) lngMonthsDiff = Abs(DateDiff("m", Date, dtmCreated)) Select Case lngHoursDiff Case Is < 24 whenCreated = lngHoursDiff & " hours ago" Case Is < 48 whenCreated = "Yesterday" Case Else Select Case lngDaysDiff Case Is < 7 whenCreated = lngDaysDiff & " days ago" Case Is < 14 whenCreated = "Last week" Case Else Select Case lngMonthsDiff Case 0 whenCreated = lngWeeksDiff & " weeks ago" End Select End Select End Select End Function