Convert into seconds

1. Senior Member
Join Date
Dec 1969
Posts
2,092

## Convert into seconds

Hi all<BR>I would like to know how to convert my string 5:17:07 into seconds?<BR><BR>thanks<BR><BR>

2. Member
Join Date
Dec 1969
Posts
63

## RE: Convert into seconds

There is no inbuilt functions.<BR>Use manual calculations to do that.<BR>

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## One easy way...

&#060;%<BR>tm = "5:07:17"<BR>secs = DateDiff( "s", CDate("0:00:00"), CDate(tm) )<BR>%&#062;<BR><BR>See the trick? We ask the DateDiff function to calculate the number of seconds that have elapsed since midnight until the time we specify.

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Hmmmm....really?

No way? Hmmm... Try the way in my post?<BR><BR>

5. Senior Member
Join Date
Dec 1969
Posts
2,092

## Do you know the steps?

Do you know the steps I must take to make it possible?<BR>Do I convert everything in seconds, hour, minutes?<BR>Is their an algorithm somewhere<BR>Thanks

6. Senior Member
Join Date
Dec 1969
Posts
2,092

## Thanks it works

.

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Surely *YOU* know the steps?

This is hopefully an "algorithm" that you deal with every single day in real life!<BR><BR>How many seconds in a minute?<BR><BR>How many minutes in an hour? <BR><BR>So all you do is<BR><BR>numberOfSeconds = hour * 3600 + minute * 60 + second<BR><BR>Right?<BR><BR>As to how you get the numbers out of the string: Split.<BR><BR>SO...<BR><BR>&#060;%<BR>temp = Split("5:40:17")<BR>numSeconds = 3600 * temp(0) + 60 * temp(1) + temp(2)<BR>%&#062;<BR><BR>Just as easy as the other way I showed.<BR><BR>

8. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## Small BOBOO

temp = Split("5:40:17")<BR>should be<BR>temp = Split("5:40:17", ":")<BR><BR>

9. Senior Member
Join Date
Dec 1969
Posts
96,118

## WHACK!

As in "Whack the Mole." Thanks, Akhilesh.<BR><BR>

#### Posting Permissions

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