Solved

Calculate number of seconds in a given time

Posted on 2014-03-14
4
236 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 33

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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