Solved

Calculate number of seconds in a given time

Posted on 2014-03-14
4
229 Views
Last Modified: 2014-03-14
Hi guys,

Using ASP/VB6

If I have a given time - say 04:00:20 AM (that's 4 hours, 0 minutes and 20 secs)

I am looking for a function which will give me the total number of seconds in the given time and also a function that does the same thing for minutes (rounding the seconds up or down using 30 second intervals)

MTIA

DWE
0
Comment
Question by:dwe0608
  • 2
4 Comments
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 39929105
If you split the given time on the space, then split the first element of the resulting array on the colon, you would end up with an array containing three elements. From there, you can calculate the seconds by:
((<element 1> * 60) + <element 2>) * 60 + <element 3>

For minutes, the calculation is similar:
(<element 1> * 60) + <element 2> + iif(<element 3> >= 30, 1, 0)

If you need to concern yourself with AM/PM, check if the first array's second element is "PM", and if so, add 12 to the hours component (<element 1> in the formulas).
0
 
LVL 26

Assisted Solution

by:Shaun Kline
Shaun Kline earned 250 total points
ID: 39929111
Actually, even easier would be to use the DATEDIFF function. Just build a date to include as part of your time, and do a date diff between that date/time and just the date.

I.e. use '3/14/2014' as the start date, and '3/14/2014 4:00:20 AM' as your second date.
0
 
LVL 32

Accepted Solution

by:
Big Monty earned 250 total points
ID: 39929202
just use the following:

timeToCheck = "1/1/2000 04:00:20 AM"
timeStart = "1/1/2000 00:00:00 AM"
numSecs = datediff( "s", timeStart, timeToCheck )
numMins = datediff( "m", timeStart, timeToCheck )
0
 
LVL 1

Author Closing Comment

by:dwe0608
ID: 39930374
Thanks guys

timeToCheck = "1/1/2000 04:00:20 AM"
timeStart = "1/1/2000 00:00:00 AM"
numSecs = datediff( "s", timeStart, timeToCheck )
numMins = datediff( "n", timeStart, timeToCheck )

"n" is for mins ....
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now