Calculating How Many Days Until a Pre-Defined Recurring Date
Written by Mark Voss published 27th Feb 2006 | Comment on this article
In this example I've used Christmas day as the annually recurring date.
All you need to do is to is ammend the recurring_date and the text Christmas day (on the two Response.Write lines) in the script below to your annually recurring date.
<%
Dim recurring_date, days_to_recurring_date
recurring_date="25/12/2006"
days_to_recurring_date = DateDiff("d",Date,recurring_date)Do While days_to_recurring_date < 0
recurring_date = DateAdd("yyyy",1,recurring_date)
days_to_recurring_date = DateDiff("d",Date,recurring_date)
LoopIf DateDiff("d",Date,recurring_date) > 0 Then
Response.Write "It is " & days_to_recurring_date & " days until Christmas day"
Else
Response.Write "It is Christmas day today."
End If
%>
The script will always output the number of days until next Christmas Day even if the recurring date you set is in the past.