# Convert seconds to HH:MM

Hi

I have a field i am getting from the database 'Seconds' as an int.

How in my crystal formula can i convert the int to the format HH:MM ?

It seems simple but this is not working....

Dim hr As Number 'to hold hrs part
Dim mn As Number 'to hold minutes
Dim sc As Number 'to hold seconds
Dim r1 As Number 'to hold reminders
Dim r2 As Number 'to hold reminders
Dim str As String 'to hold string hrs
Dim str1 As String 'to hold string minutes
Dim str2 As String 'to hold string seconds
Dim start as number

start = int({Summary.intInCourse}/{Summary.intUserTotal})
hr=start/ 3600 'get hours
r1=Remainder (start,3600 ) 'rest of seconds after hours taken out
mn=int(r1 / 60) 'get minutes
r2=Remainder (r1,60 ) 'rest of the seconds

'Convert all values in to strings to format in to "00" and to remove decimals
str=CStr (hr)
str1=CStr (mn)
str2=CStr (r2)

'to get rid off the decimal values
str = left(str, len(str)-3)
str1 = left(str1, len(str1)-3)
str2 = left(str2, len(str2)-3)

'format in to "00"
if len(str)<=1 then
str="0" & str
else
str= str
end if
if len(str1)<=1 then
str1="0" & str1
else
str1= str1
end if
if len(str2)<=1 then
str2="0" & str2
else
str2 = str2
end if
formula= str & ":" & str1 & ":" & str2

any ideas??

Crystal Reports

Last Comment
peter57r
peter57r

Hi martmac,

cstr(numSecs\3600) & ":" & cstr((numsecs mod 3600)\60

('\' not '/')

Pete
janmarini

Try Ctime(hr, min, sec) or TimeSerial(hr,min,sec)
bdreed35

THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
bdreed35

oops, last line of formula should be this:

formula=cstr(hr,"00") & ":" & cstr(mn,"00") & ":" & cstr(r2,"00")
osiris247

thanks peter nearly there....just need to strip the decimal place off.

hr = round((start\3600),0)
mn = round((start mod 3600),0)\60

seems has no affect??
peter57r

Whoops......

cstr(numSecs\3600,"0") & ":" & cstr((numsecs mod 3600)\60,"00" )

Pete
Crystal Reports

Crystal Reports is a business intelligence application from SAP SE. It is used to graphically design data connections and report layouts from a wide range of data sources including Excel spreadsheets, Oracle, SQL Server databases and Access databases, BusinessObjects Enterprise business views, and local file-system information. Report designers can place fields from these sources on the report design surface, and can also deploy them in custom formulas (using either BASIC or Crystal's own syntax), which are then placed on the design surface. Crystal Reports also supports subreports, graphing, and a limited amount of GIS functionality.

36K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts

TRUSTED BY