Link to home
Start Free TrialLog in
Avatar of Wayne Barron
Wayne BarronFlag for United States of America

asked on

ASP Classic (vb) convert minutes to seconds ( 90 = 5400 )

Hello, All.

working on the last part of this project.
At least for the math anyway.

I have all my time in the database set as minutes.
90 = 1:30:00
So, what I need to do now, is convert the minutes into seconds.
90 = 5400

Everything I am finding is for the reverse.
Seconds into Minutes or hours.
Nothing for the opposite.

Any idea's on this one?
ASKER CERTIFIED SOLUTION
Avatar of Chinmay Patel
Chinmay Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Wayne Barron

ASKER

How would I use this?

And is this for converting minutes to seconds?

Say, my minute's record from the DB is.
MyTime = 90
First I need the answer :)

This conversion.. you want to do it in ASP Classic or on the database side?

Then I already wrote assuming you want to do it in ASP Classic
For ASP Classic just multiply the minutes to 60 i.e.
secs = mins * 60

Open in new window


And yes 1 minute has 60 seconds , so if you multiply 1 minute to 60 it gives you the total number of seconds in a minute, now assuming you have N minutes(In this case, let's say 90), and you multiply it with 60 then the result would be 90 * 60 = 5400.

We can run this trick everywhere on your database, in your ASP Classic code and even on the client side where you might be displaying the data to your end users. So you have to answer the first question I asked

This conversion.. you want to do it in ASP Classic or on the database side?
I am so sorry about that.
I was fixing to leave the house to run up the road when I looked down at the computer and saw your response.
And DID NOT test before assuming.

Works like a charm.
Thanks, Chinmay

Wayne
:) No worries. I am glad I could help.
To add on what Chinmay has provided, wherever you have something like this that could be on multiple pages, create a function and place the function in a functions page that gets included at the top of every page.

function getSeconds(mins)
     secs = mins * 60
      getSeconds = secs
end function

Open in new window

And as an add on
function getSeconds(time)
     if(InStr(time,":")>0 then
  
          t=split(time,":")  ' convert 1:30:00 to an array
          h=cint(t(0))                  'hours  - cint removes leading zeros and converts to integer
          m=cint(t(1))                 'minutes
          s=cint(t(2))                   seconds

          secs = s + (m*60) + (h*60*60)

     else

          secs = mins * 60

     end if

     getSeconds = secs
end function

Open in new window


With this function you should be able to do getSeconds("1:30:00") or getSeconds(90) and come up with the same answer.