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

DateDiff Problem

Status
Not open for further replies.

jsiimml

Programmer
Feb 14, 2006
10
GB
Hi, I have a lottery script on my forum and I need to work out the next draw date based on todays date and the datetime field stored inthe database. So far I've got:

vblNextDrawDays = DateDiff("d", Now(), vblDrawsArray(1,0))
vblNextDrawHours = DateDiff("h", Now(), vblDrawsArray(1,0))
vblNextDrawMinutes = DateDiff("n", Now(), vblDrawsArray(1,0))

Next Draw in <%=vblNextDrawDays%> days <%=Abs(vblNextDrawHours)%> hours and <%=Abs(vblNextDrawMinutes) - Abs(vblNextDrawHours) * 60%> minutes

but it doesn't always work. Sometimes it's right and other times it's wrong (such as today the draw is at midnight tonight but it still says 1 day remaining).

Appreciate if you could help. Thanks
 
Problem solved, I googled my question and come up with:

vblNextDrawMinutes = DateDiff("n", Now(), vblDrawsArray(1,0))
vblNextDrawHours = vblNextDrawMinutes \ 60 ' note the \ returns an integer when it divides
vblNextDrawDays = vblNextDrawHours \ 24
vblNextDrawHours = vblNextDrawHours - (vblNextDrawDays * 24)
vblNextDrawMinutes = vblNextDrawMinutes - (vblNextDrawHours * 60)

Next Draw in <%=vblNextDrawDays%> days <%=vblNextDrawHours%> hours and <%=vblNextDrawMinutes%> minutes

Note vblDrawsArray(1,0) is the next draw date/time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top