This topic is locked

Format seconds to time

9/26/2007 6:31:55 AM
ASPRunnerPro General questions
B
boomer3828 author

Hello,
I'm having a time field from an oracle database.

The problem is that the amount of time is in seconds. For example 4800 seconds.

The question now: Is it possible to convert the seconds to, in this case, 1 hour and 20 minutes. (1:20:00)

Anybody????
Thanks in advance

D
dlangham 9/26/2007

Hi,
You could use this function below:

<%

function oracletime(dbOracleTime)

oracletime = DateAdd("s", dbOracleTime, "00:00:00")

end function
Response.write oracletime(4800)
%>


This will return: 01:20:00

B
boomer3828 author 9/27/2007

Thank for your answer.

I'm quit new about ASPRunner, so where do I put this code.

I made a function in the past wich gives me the time in text ( 1 hour, 40 minutes etc...) and tried to fit it in as wel without anny succes.

ASPRunner saves me a lot of time but as long as I cant put in a function.... so please help.
By the way... the field I'm connecting to is called WT_DURATION.
Forgive my stupidity.... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=21698&image=1&table=forumreplies' class='bbc_emoticon' alt=';)' />

D
dlangham 9/27/2007

I have not used any custom functions recently with asprunner, but I will try and point you in the right direction if I am wrong then someone should correct me, firstly try putting the function below in the aspfunctions.asp page as this page will be referenced on the list page.

<%

function oracletime(dbOracleTime)

oracletime = DateAdd("s", dbOracleTime, "00:00:00")

end function

%>


Then call the function from your list page referencing your field something along the lines of below:

<%

Response.write (oracletime("WT_DURATION"))

%>


The syntax might not be correct for the latest version, but give it a try.

B
boomer3828 author 10/3/2007

To Bad.... it works within pages I make by myself, but doesn't seem to work within ASPRunner.

I already have a report where I convert seconds to text (see code below) but can't get it fit into ASPRunner.

The difference is that the "funtion" and the "repsonse write" stay within the same page.

Thanks for your time, your code is a great help in other reports.
[codebox]<%

Function SecondsToText(Seconds)

Dim bAddComma

Dim Result

Dim sTemp
If Seconds <= 0 Or Not IsNumeric(Seconds) Then

SecondsToText = "0 seconds"

Exit Function

End If
Seconds = Fix(Seconds)
If Seconds >= 86400 Then

days = Fix(Seconds / 86400)

Else

days = 0

End If
If Seconds - (days 86400) >= 3600 Then

hours = Fix((Seconds - (days
86400)) / 3600)

Else

hours = 0

End If
If Seconds - (hours 3600) - (days 86400) >= 60 Then

minutes = Fix((Seconds - (hours 3600) - (days 86400)) / 60)

Else

minutes = 0

End If
Seconds = Seconds - (minutes 60) - (hours 3600) - _

(days * 86400)
If Seconds > 0 Then Result = Seconds & " second" & AutoS(Seconds)
If minutes > 0 Then

bAddComma = Result <> ""
sTemp = minutes & " minute" & AutoS(minutes)

If bAddComma Then sTemp = sTemp & ", "

Result = sTemp & Result

End If
If hours > 0 Then

bAddComma = Result <> ""
sTemp = hours & " hour" & AutoS(hours)

If bAddComma Then sTemp = sTemp & ", "

Result = sTemp & Result

End If
If days > 0 Then

bAddComma = Result <> ""

sTemp = days & " day" & AutoS(days)

If bAddComma Then sTemp = sTemp & ", "

Result = sTemp & Result

End If
SecondsToText = Result

End Function

%>

[/codebox]

[codebox]<TD><%Response.Write (SecondsToText(Clng(objRS("WT_DURATION")))) %> Â </TD>[/codebox]

Sergey Kornilov admin 10/4/2007

I recommend you to post your application to Demo Account and send the URL to support@xlinesoft.com.