ASP Classic relative date function
Posted on 18.09.09 13:43:19 by Ariel G. Saputra in Classic ASP
Classic ASP has limited date time functions and because of that displaying date in advanced format becomes a bit tricky. Today i decide to add relative date function into my asp twitter library, and comes across my old post at other blog about converting ASP date into Timestamp format and vice versa, from timestamp format we simply need to calculate the time different between current time and the variable time to get relative date.
And here is the function to get relative date in Classic ASP:
'@ dependencies functions available at http://www.chazzuka.com/blog/?p=63 '@ params: '@ integer (date timestamp) '@ string (date format, read more about this format at link above) function relative_date(intTimestamp,format) if isEmpty(format) then format = "%l, %F %j%o, %Y %H:%i %A" timediff = (to_unix_timestamp(Now()))-intTimestamp if timediff<120 then relative_date = "1 minute ago" elseif timediff<3600 then relative_date = int(timediff/60)&" minutes ago" elseif timediff<7200 then relative_date = "1 hour ago" elseif timediff<86400 then relative_date = int(timediff/3600)&" hours ago" elseif timediff<172800 then relative_date = "1 day ago" elseif timediff<604800 then relative_date = int(timediff/86400)&" days ago" elseif timediff<1209600 then relative_date = "1 week ago" elseif timediff<3024000 then relative_date = int(timediff/604900)&" weeks ago" else relative_date = FormatDate(format,intTimestamp) end if end function
How to use?
Dim curDate,relativeDate curDate = to_unix_timestamp(Now()) relativeDate = relative_date(curDate,"%l, %F %j%o, %Y %H:%i %A") response.write relativeDate
Any suggestions and corrections to improve this codes are welcome

0 Comments For This Post
1 Trackbacks For This Post
ASP Twitter Lib Update Says:
[...] another small updates I made on ASP Twitter Lib, a couple functions changes, and adding relative date function this could be done by importing ASP Timestamp Date function at my old post which is based on a [...]