Calculating Time... Help!

1. Member
Join Date
Dec 1969
Posts
67

## Calculating Time... Help!

Hello,<BR><BR>I need to perform the following calculation to produce "track time remaining:( trackStartTime + sTrackLength - currentTime )<BR><BR>I&#039;ve given it my best shot but the results are less than favorable. Here is my current code to display time remaining in "minutes:seconds".<BR><BR>Dim trackStartTime, sTrackMinutes, sTrackSeconds, sTrackLength, currentTime, sTrackEndTime, sTimeRemaining<BR><BR>1. trackStartTime = FormatDateTime(DateAdd("s",sTime,"12/31/1969 8:00PM"),3)<BR><BR>2. sTrackMinutes = "78"<BR><BR>3. sTrackSeconds = "56"<BR><BR>4. sTrackLength = sTrackMinutes & ":" & sTrackSeconds<BR><BR>5. currentTime = formatDateTime(now(),3)<BR><BR>6. sTrackEndTime = formatdatetime(dateadd("n", + cDate(sTrackMinutes ), dateadd("s",+ cDate(sTrackSeconds), trackStartTime)), 3)<BR><BR>7. sTimeRemaining= formatdatetime(dateadd("n", - Minute(currentTime), dateadd("s",- Second(currentTime), sTrackEndTime )),3)<BR><BR>You&#039;re help would be much appreciated and welcomed.

2. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: Calculating Time... Help!

Do you know the datediff function?

3. Member
Join Date
Dec 1969
Posts
67

## RE: Calculating Time... Help!

Sort of, would that make the difference?

4. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: Calculating Time... Help!

to be honest, I didn&#039;t read your whole Q.<BR><BR>I would do<BR><BR>SecondsRemaining = TotalTrackTimeInSeconds - (DATEDIFF in seconds between starttime and currenttime)<BR><BR>this gives you the remaining time in seconds.<BR><BR><BR><BR>

5. Member
Join Date
Dec 1969
Posts
67

## RE: Calculating Time... Help!

Would I have to do perform a datediff for the minute and second? If so, what do I do with the results of each? That confuses me.<BR><BR>Thanks in advance,

6. Member
Join Date
Dec 1969
Posts
67

## RE: Calculating Time... Help!

TotalTrackTimeSeconds = dateadd("s", sTrackSeconds, trackStartTime)<BR><BR>SecondsRemaining = TotalTrackTimeSeconds - dateDiff("s", trackStartTime, currentTime)<BR><BR>this produces this format: 9:09:30 AM<BR><BR>don&#039;t this is correct.

7. Member
Join Date
Dec 1969
Posts
67

## RE: Calculating Time... Help!

Would anybody else care to assistn me with this. I&#039;d greatly appreciate any help.<BR><BR>Thanks in advance,

8. Senior Member
Join Date
Dec 1969
Posts
7,686

## RE: Calculating Time... Help!

When you have the totaltime in seconds you can&#039;t use the format datetime function.<BR><BR>Divide it by 60 for the minuts, and use the MOD function for the remaining seconds<BR><BR>Let&#039;s say the TotalSecondsRemaining = 325<BR><BR>325/60 = 5.41, to round this we use th FIX() function<BR><BR>TotalMinutes = FIX(5.41)<BR>TotalSeconds = 325 MOD 60<BR><BR>Get the idea?

9. Member
Join Date
Dec 1969
Posts
67

## RE: Calculating Time... Help!

Thank you, here&#039;s what I&#039;ve come up with:<BR><BR>TimeNow = formatDateTime(now(),3)<BR><BR>sMixMinutes = 72<BR>sMixSeconds = 37<BR><BR>totalTrackTime = formatdatetime(dateadd("n", sMixMinutes, dateadd("s", sMixSeconds, sTime)), 3)<BR><BR>startEndDiff = dateDiff("s", totalTrackTime, TimeNow)<BR>Minutes = startEndDiff /60<BR>TotalMinutes = FIX(Minutes) <BR>TotalSeconds = startEndDiff MOD 60<BR><BR>produces: -69:-6 <BR><BR>how can I format that result?<BR><BR>Thank again in advance.<BR><BR>Qwest.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•