ASP calculation Time Date

Source: Internet
Author: User
Tags datetime

Public Function Timetodiff (DateTime)
If IsDate (DateTime) Then
Dim Tsecond:tsecond=datediff ("s", Datetime,now ())
If tsecond<60 Then '//within one minute
Timetodiff= "just"
End If
If tsecond>=60 and tsecond<3600 Then '//within one hour
Timetodiff=datediff ("n", Datetime,now ()) & "Minutes Ago"
End If
If tsecond>=3600 and tsecond<86400 Then '//within one day
Timetodiff=datediff ("H", Datetime,now ()) & "Hours Ago"
End If
If tsecond>=86400 and tsecond<2592000 Then '//One months
Timetodiff=datediff ("D", Datetime,now ()) & "Days Ago"
End If
If tsecond>=2592000 and tsecond<31536000 Then '//One year
Timetodiff=datediff ("M", Datetime,now ()) & "months ago"
End If
If tsecond>=31536000 Then '/Other
Timetodiff=datediff ("yyyy", Datetime,now ()) & "Years ago"
End If
Else
timetodiff= "N days Ago"
End If
End Function

' Invoke method
Call Timetodiff (now ())

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.