...

View Full Version : # days left from date



startbar
07-23-2004, 11:40 AM
hi, i need a bit of code that will count down from 90 days from a
<%=objRS("Date")%> section in a database.

any ideas?

glenngv
07-23-2004, 01:11 PM
This?


dim d, d2
d = objRS("Date")
if not isnull(d) and isdate(d) then
d2 = dateadd("D", 90, d)
response.write d2
else
response.write "Null or invalid date"
end if

startbar
07-23-2004, 01:14 PM
quite possibly. I need to show the date on the page as well as the '# days left' so whats the code for the if i wanted to say:

for example.

'you have 84 days left'

thanks

glenngv
07-23-2004, 01:26 PM
How about this?


dim d, d2, daysLeft
d = objRS("Date")
if not isnull(d) and isdate(d) then
d2 = dateadd("D", 90, d)
daysLeft = datediff("D", Date(), d2)
response.write "You have " & daysLeft & " days left."
else
response.write "Null or invalid date"
end if

startbar
07-23-2004, 01:43 PM
let me try it..

startbar
07-23-2004, 01:45 PM
so it counts from the 'Date' Value?

so if the date that the entry was added was '01/01/01' and the date of viewing was '02/01/01' it would show 89 days left?

thats great, thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum