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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using datediff with asp

Status
Not open for further replies.

gsc123

Programmer
Jan 24, 2008
197
I'm tring to work out the date left and present it in a realtime format ie:

Day/Mnth/Year - 21:15:58

Got any pointers on how I should do this please


seconds=DateDiff("s",pStartDate,pEndDate)
minutes=DateDiff("s",pStartDate,pEndDate)
hours=DateDiff("h",pStartDate,pEndDate)
days=DateDiff("d",pStartDate,pEndDate)
months=DateDiff("m",pStartDate,pEndDate)
years=DateDiff("yyyy",pStartDate,pEndDate)

strText = days & ":" & months & ":" & years & ":" & hours & ":" & minutes & ":" & seconds
 
This won't give you a countdown. if your dates are, for example, 1 Jun 2009 10:00 and 2 Jun 2009 12:00 the difference in hours is 2. The difference in minutes is 120, so your scenario will show 2:120.

You need to calculate the modulus for each section based on the base of the higher section. So:

sd = "1 Jun 2009 10:00:20"
ed = "5 Jun 2009 12:15:47"
days = DateDiff("d", sd, ed)
hours = DateDiff("h", sd, ed) Mod 24
minutes = DateDiff("n", sd, ed) Mod 60
seconds = DateDiff("s", sd, ed) Mod 60
Debug.Print days & ":" & Right("0" & hours, 2) & _
":" & Right("0" & minutes, 2) & ":" & _
Right("0" & seconds, 2)

 
I wouldn't do this in asp at all though. ASP is server side. If you want this to actually be a countdown, and therefore changing every second, you're better off using javascript and doing client side.
 
I'm not really bothered about the client side tick but should calculating the time from now to the end
 
Well at least it works thxs but can you solve this problem

I have Now() as the date now to the end date in this format-
6/5/2009 21:15:58 from the DB but the Now() function is this way round

5/31/2009 10:03:17

So today its saying its

5d 11h 12m 41s - which is wrong?

 
Can the days off the date be moved to the front rather than 05/31/2009?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top