Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP Countdown to Date

Status
Not open for further replies.

aojonesoa

Technical User
Apr 25, 2001
40
US
My niece is getting married and I would like to put a countdown to her wedding date and time. I have found some sample code, but it doesn't work exactly right. For example, when the time is before the time of the wedding, it doesn't work right, it would either be negative minutes, or more than 60.

Does anyone have the code to make this work right?

Thanks!
aojonesoa:)
 
Use DateDiff.
Here is part of the documentation from the MS website:
Code:
DateDiff Function
Returns the number of intervals between two dates. 

DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]])

The DateDiff function syntax has these parts:

Arguments
interval

Required. String expression that is the interval you want to use to calculate the differences between date1 and date2. See Settings section for values.

date1, date2

Required. Date expressions. Two dates you want to use in the calculation.

firstdayofweek

Optional. Constant that specifies the day of the week. If not specified, Sunday is assumed. See Settings section for values.

firstweekofyear

Optional. Constant that specifies the first week of the year. If not specified, the first week is assumed to be the week in which January 1 occurs. See Settings section for values.

Settings
The interval argument can have the following values:

Setting Description 
yyyy Year 
q Quarter 
m Month 
y Day of year 
d Day 
w Weekday 
ww Week of year 
h Hour 
n Minute 
s Second 

The following example uses the DateDiff function to display the number of days between a given date and today: 

Function DiffADate(theDate)
   DiffADate = "Days from today: " & DateDiff("d", Now, theDate)
End Function
Wushutwist
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top