Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calculate number of seconds in a given time

Posted on 2014-03-14
4
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

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 27

Assisted Solution

by:Shaun Kline
Shaun Kline earned 750 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 34

Accepted Solution

by:
Big Monty earned 750 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

636 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