PDA

View Full Version : Using the DateDiff() Function


admin
05-29-2003, 03:49 PM
You can use the DateDiff() function to calculate the difference between two dates. In this example, we query a database of links and if the link is less than or = to being 14 days old we place an image beside the link. The DateDiff function uses three arguments:

- a date or time interval (i.e. d for day, m for month, h for hour, etc...)
- a date
- another date

In the below example our database of links has a field named Datum which contains the date the link was added to the database.

The Datum field is compared to the current date, if the difference between these two dates is 14 days or less we add an image next to the link.

<%
fromDate = rs("Datum")
'fromDate is the value in the Datum field

toDate = Date()
'toDate uses the Date() function which gives the current date

If DateDiff("d",fromDate,toDate) <= 14 Then
Response.Write "<img src=""../new.gif"">"
End If
%>